input
stringlengths 51
42.3k
| output
stringlengths 18
55k
|
|---|---|
Moving items in Dual Listboxes <p>How can I move items from one list box control to another listbox control using JavaScript in ASP.NET?</p>
|
<p>If you're happy to use jQuery, it's very, very simple.</p>
<pre><code>$('#firstSelect option:selected').appendTo('#secondSelect');
</code></pre>
<p>Where #firstSelect is the ID of the select box.</p>
<p>I've included a working example here:</p>
<p><a href="http://jsbin.com/aluzu">http://jsbin.com/aluzu</a> (to edit: <a href="http://jsbin.com/aluzu/edit">http://jsbin.com/aluzu/edit</a>)</p>
|
How to update a text or ntext field in SQL Server 2000 <p>So I need to update a text field. Neither the UPDATE statement or the WRITETEXT statement work when used below</p>
<pre><code>CREATE TABLE MyTable (IDField int, MyField text)
INSERT INTO MyTable (IDField) SELECT 1
DECLARE @Data1 varchar(8000), @Data2 varchar(8000), @ptrval binary(16)
SELECT @Data1 = REPLICATE('1',8000)
SELECT @Data2 = REPLICATE('2',8000)
-- this sets MyField to string of only 8000 characters
UPDATE MyTable SET MyField = @Data1 + @Data2 WHERE IDField = 1
SELECT @ptrval = TEXTPTR(MyField )
FROM MyTable
WHERE IDField = 1
-- this causes an error: Incorrect syntax near '+'.
--WRITETEXT MyTable.MyField @ptrval @Data1 + @Data2
</code></pre>
<p>How am I supposed to do this when local variables cannot be of type TEXT? (If I had SSQL Server 2005 I would use varchar(max) - but I don't)</p>
|
<p>Try using UPDATETEXT instead</p>
<pre><code>WRITETEXT MyTable.MyField @ptrval @Data1
UPDATETEXT MyTable.MyField @ptrval 8000 NULL @Data2
</code></pre>
<p>The insert offset is zero based so 8000 should write into the 8001st character.
The delete offset is null as a value of NULL deletes all data from the insert_offset position to the end of the existing text. </p>
<p>Ref: <a href="http://msdn.microsoft.com/en-us/library/ms189466.aspx">http://msdn.microsoft.com/en-us/library/ms189466.aspx</a></p>
<p>Do not forget nvarchar (which you should use with ntext field) have a maximum capacity of half the varchar fields that you are using so your block sizes need to be reduced to 4000 in that case. </p>
|
Spreadsheet-like control for a web application? <p>A client of mine is looking to convert a critical 'application' based on multiple (very complex) spreadsheets into a web app. As part of this they'd like some of the web pages they use to enter/model data to resemble a spreadsheet as much as possible.</p>
<p>I'd be interested to know if anyone has any experience/recommendations for embeddable controls that could do this better than standard html/javascript/ajax code - although suggestions for Javascript frameworks that could do this are welcome too. I'm thinking mainly of ActiveX, Flex, Java or similar controls, commercial or open source are fine.</p>
<p>The coding languages to be used and platform is still open to debate, so ASP.NET against IE or PHP/Flex against Firefox, or some other combination is fine - this will be driven by the business requirement not the platform. </p>
<p>Functionality is of course the main driving force, but it's always useful to have nice looking eye candy so skinable and cool is a plus. With reference to Javascript frameworks I''ve previously used Dojo and Mootools, but I'd prefer something with a bit more snap.</p>
|
<p>I'd say this comes down to data grids.</p>
<p>For Javascript frameworks: Jquery has 'plugins' like <a href="http://trirand.com/jqgrid/jqgrid.html" rel="nofollow">this</a>.
Serverside: Telerik has asp.net controls like <a href="http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/Overview/DefaultCS.aspx" rel="nofollow">this</a>.</p>
<p>It really comes down to what platform mix you want to use.</p>
<p>Also, why do you want to bind an asp.net page to IE instead of Firefox?</p>
<p>For a web application, my recommendation would be a mix of asp.net mvc and jquery. JQuery is in my view the best and most stable JavaScript framework out there. The problem is that asp.net mvc is still in ctp phase and it's probably not 'supported' and 'stable' enough in some eyes. I already finished a mid-scale commercial web app based on the mixture and was pleased with it.</p>
|
Initialising a struct variable to Nullable<int> <p>Is there a way to declare a variable as Nullable in c#?</p>
<pre><code>struct MyStruct {
int _yer, _ner;
public MyStruct() {
_yer = Nullable<int>; //This does not work.
_ner = 0;
}
}
</code></pre>
|
<p>_yer must be declare as int? or Nullable<int>.</p>
<pre><code> int? _yer;
int _ner;
public MyStruct(int? ver, int ner) {
_yer = ver;
_ner = ner;
}
}
</code></pre>
<p>Or like this:</p>
<pre><code> Nullable<int> _yer;
int _ner;
public MyStruct(Nullable<int> ver, int ner) {
_yer = ver;
_ner = ner;
}
}
</code></pre>
<p><strong>Remember that structs cannot contain explicit parameterless constructors.</strong></p>
<pre><code>error CS0568: Structs cannot contain explicit parameterless constructors
</code></pre>
|
What's the term for design ala "object.method1().method2().method3()"? <p>What's the term for this design?</p>
<pre><code>object.method1().method2().method3()
</code></pre>
<p>..when all methods return *this?</p>
<p>I found the term for this a while ago, but lost it meanwhile.
I have no clue how to search for this on google :)
Also if anyone can think of a better title for the question, feel free to change it.</p>
<p>Thanks</p>
<p><strong>Update-Gishu</strong>: After reading about it, I feel that your question is misleading w.r.t. code snippet provided.. (Feel free to rollback)</p>
<p><em>Method Chaining</em></p>
<pre><code>object.method1().method2().method3()
</code></pre>
<p><em>Fluent Interfaces</em></p>
<pre><code>private void makeFluent(Customer customer) {
customer.newOrder()
.with(6, "TAL")
.with(5, "HPK").skippable()
.with(3, "LGV")
.priorityRush();
}
</code></pre>
|
<p>Looks to me like you are describing a fluent interface. Ive also heard it referred to as pipelineing or chaining.</p>
<p>Update-Gishu: <a href="http://martinfowler.com/bliki/FluentInterface.html">http://martinfowler.com/bliki/FluentInterface.html</a> </p>
|
Directory of APIs/WebServices - where do I find one? <p>Where do I find a directory where a lot of APIs or Webservices are collected? I'd like to generate a Web Site getting its content from different services, but I assume that spidering together the content is not legal (e.g. getting the latest financial data from finance.yahoo.com).</p>
<p>So I would like to have a list of APIs and WebServices (not only financially related) where I can search for such services. It would also help to generate 'new' ideas, while reading through the list => I'm sure there are a lot of services I do not even think of.</p>
|
<p>I'd suggest a visit to <a href="http://www.programmableweb.com/" rel="nofollow">ProgrammableWeb</a>, especially its <a href="http://www.programmableweb.com/apis/directory" rel="nofollow">API Directory</a>.</p>
|
Encrypt on iSeries <p>What tools are available to encrypt or password-protect a file stored on the IFS?</p>
<p>*integrated file-system, accessible from Windows</p>
|
<ol>
<li>You could setup object security so only certain users can view the file.</li>
<li>There are encryption tools available for purchase. There is also some built-in APIs for encrypting. </li>
</ol>
<p>Here are some resources to look into:</p>
<ol>
<li><a href="http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/qc3Scenario.htm" rel="nofollow">Scenario: Key Management and File Encryption Using the Cryptographic Services APIs</a></li>
<li><a href="http://www.ibmsystemsmag.com/i5/june04/administrator/8475p4.aspx" rel="nofollow">The Next Step in Security</a></li>
<li><a href="http://www.itjungle.com/fhg/fhg042705-story01.html" rel="nofollow">A Simple Encryption/Decryption Algorithm for Numbers</a></li>
<li><a href="http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/catcrypt.htm" rel="nofollow">Cryptographic Services APIs</a></li>
</ol>
<p>Most of these articles deal with encrypting data in a table, but the concepts should help you encrypt a file on the IFS.</p>
|
Version control "in the clouds" <p>I'm a developer who works on both individual and group projects using Microsoft Visual Studio. I could setup one of several different source control packages, such as VSS, SourceGear Vault or SVN on a server of my own and access them remotely; however, I don't want to deal with the hassle of setting it up, configuring it, etc.</p>
<p>Does anyone offer a hosted source control service?</p>
|
<p>For Git, check out <a href="http://github.com">GitHub</a>. Good packages, used by an awful lot of opensource projects. Considered to be one of the best hosting experiences for git.</p>
|
Any experience with the Deliverance system? <p>My new boss went to a speech where Deliverance, a kind of proxy allowing to add skin to any html output on the fly, was presented. He decided to use it right after that, no matter how young it is.</p>
<p>More here :</p>
<p><a href="http://www.openplans.org/projects/deliverance/introduction" rel="nofollow">http://www.openplans.org/projects/deliverance/introduction</a></p>
<p>In theory, the system sounds great when you want a newbie to tweak your plone theme without having to teach him all the complex mechanisms behind the zope products. And apply the same theme on a Drupal web site in one row.</p>
<p>But I don't believe in theory, and would like to know if anybody tried this out in the real world :-)</p>
|
<p>Having used Plone professionally for the last 4 years or so, and Deliverance on 4 commercial sites, I would advise all new front end developers (and old hands alike) to use Deliverance to theme Plone sites.</p>
<p>It is <em>much</em> easier to learn (a couple of weeks Vs couple of months) and potentially much more powerful than the old, confused, methods - few of which you will still need (and even then at a much later point in the life of the site).</p>
<p>Not only that, but it uses XPath and CSS selectors and can be used on non-Plone sites, so the time invested is easily transferable.</p>
|
Deploy time Webservice location <p>In my Visual Studio Web application project I am adding a reference to a web service. When I add a web reference the following list of files gets generated. </p>
<ul>
<li>Reference.map</li>
<li>Reference.vb</li>
<li>Reference.disco</li>
<li>Reference.wsdl</li>
</ul>
<p>All these files contains the url pointing to the web service. Even when I move it to a machine without visual studio, it works fine. But if I intend to change the url of the web service, I need to modify <em>all these four files</em> by editing them using notepad. </p>
<p>Instead of this, is there any way I can have the url in the config file and just change it in one place and the web service are pointed to the new location.</p>
<p>I am using framework 1.1. </p>
|
<p>Set the web service reference "Url Behaviour" property to Dynamic, and the address will be cofigured in your app.config file....</p>
<p>The app.config file should then contain something like </p>
<pre><code> <applicationSettings>
<Exceptions.Properties.Settings>
<setting name="Exceptions_CentreService_CentreService" serializeAs="String">
<value>http://localhost/CentreServiceCompatibility/CentreService.asmx</value>
</setting>
</Exceptions.Properties.Settings>
</applicationSettings>
</code></pre>
|
Does anybody familiar with big projects that was build with linqtoSql ORM? <p>does it cost cost effective ?
how can i profile the Sql calls to the server?</p>
|
<p>I don't know what is big for you, but you are using a project running on LINQ to SQL right now, that's Stackoverflow.</p>
<p>Also you would find interesting looking at <a href="http://www.codeproject.com/KB/linq/performance_comparisons.aspx" rel="nofollow">this</a> performance benchmarks. <a href="http://jdconley.com/blog/archive/2007/11/28/linq-to-sql-surprise-performance-hit.aspx" rel="nofollow">This</a> guy profiled LINQ to SQL using ANTS profiler, although I know that most profilers would work. </p>
<p>But I think what you are looking for is setting your <a href="http://www.davidhayden.com/blog/dave/archive/2007/08/17/DataContextLogLoggingLINQToSQLOutputConsoleDebuggerOuputWindow.aspx" rel="nofollow">DataContext.Log</a> property to something like Console but with profiling added, if think you can extend Console and make your own query profiler.</p>
|
Best way for retrieving single record results in LINQ to SQL <p>If I query a table with a condition on the key field as in:</p>
<pre><code> var user = from u in dc.Users
where u.UserName == usn
select u;
</code></pre>
<p>I know that I will either get zero results or one result. Should I still go ahead and retrieve the results using a for-each or is there another preferred way to handle this kind of situation. </p>
|
<p>Try something like this:</p>
<pre><code>var user = (from u in dc.Users
where u.UserName == usn
select u).FirstOrDefault();
</code></pre>
<p>The <a href="http://msdn.microsoft.com/en-us/library/bb549141.aspx">FirstOrDefault</a> method returns the first element of a sequence that satisfies a specified condition or a default value if no such element is found.</p>
|
Are threads reused between requests in ASP.Net? <p>I'm just wondering if the same thread is used for each session, or if its dangerous to count on a particular thread between requests. What I'm getting at, is can I use thread static storage?</p>
|
<p>The short answer is yes. The thread used for a request is returned to the thread pool and can be used to service other requests. They are NOT session specific, and to answer your second question, you should never count on a particular thread being available for subsequent requests on a particular session. Because of this, it is a very bad idea to use thread static variables in ASP.Net.</p>
|
Best Server-side .NET PDF editing library <p>What's the best .NET PDF editing library available, and why?</p>
<p>It needs to be used on an IIS web-server.
Specifically, I need to edit a PDF which was generated by reporting services.</p>
<p>Factors I'm interested in:</p>
<ol>
<li>Speed</li>
<li>Memory Consumption</li>
<li>Price</li>
<li>Quality of documentation</li>
<li>Library stability</li>
<li>Size of library</li>
<li>Whatever else you think is important</li>
</ol>
|
<p>Have a look at <a href="http://itextsharp.sourceforge.net/">iTextSharp</a>. iTextSharp is a port of the <a href="http://www.lowagie.com/iText/">iText</a> , a free Java-Pdf library.</p>
<p>To quote iText:</p>
<p>You can use iText to:</p>
<ul>
<li>Serve PDF to a browser</li>
<li>Generate dynamic documents from XML files or databases</li>
<li>Use PDF's many interactive features</li>
<li>Add bookmarks, page numbers, watermarks, etc.</li>
<li>Split, concatenate, and manipulate PDF pages</li>
<li>Automate filling out of PDF forms</li>
<li>Add digital signatures to a PDF file</li>
<li>And much more...</li>
</ul>
|
Tool for parsing smtp logs that finds bounces <p>Our web application sends e-mails. We have lots of users, and we get lots of bounces. For example, user changes company and his company e-mail is no longer valid.</p>
<p>To find bounces, I parse smtp log file with log parser.</p>
<p>Some bounces are great, like <code>550+#5.1.0+Address+rejected+user@domain.com</code>. There is <code>user@domain.com</code> in bounce.</p>
<p>But some do not have e-mail in error message, like <code>550+No+such+recipient</code>.</p>
<p>I have created simple ruby script that parses logs (uses log parser) to find which mail caused something like <code>550+No+such+recipient</code>.</p>
<p>I am just surprised that I could not find a tool that does it. I have found tools like zabbix and splunk for log analysis, but they look like overkill for such simple task.</p>
<p>Anybody knows a tool that would parse smtp logs, find bounces and e-mails that cause them?</p>
<p><strong>Edit:</strong> smtp server is microsoft smtp server.</p>
|
<p>This <a href="http://scriptolog.blogspot.com/2007/08/smtp-log-parsing.html">article</a> is exactly what you are looking for. It is based on the great tool <a href="http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx">log parser</a>.</p>
<blockquote>
<p>Log parser is a powerful, versatile
tool that provides universal query
access to text-based data such as log
files, XML files and CSV files, as
well as key data sources on the
Windows® operating system such as the
Event Log, the Registry, the file
system, and Active Directory®. You
tell Log Parser what information you
need and how you want it processed.
The results of your query can be
custom-formatted in text based output,
or they can be persisted to more
specialty targets like SQL, SYSLOG, or
a chart. Most software is designed to
accomplish a limited number of
specific tasks. Log Parser is
different... the number of ways it can
be used is limited only by the needs
and imagination of the user. The
world is your database with Log
Parser.</p>
</blockquote>
|
Krypton Form not showing up in Visual Studio Professional 2008 <p>I have just installed the Krypton Toolkit 3.0.6 from component Factory.
I find that in the create new Project Dialog Box , Krypton Form does not show up as an option. I am sure it used to show up ( and I have actually used it in an earlier version of krypton toolkit).But after the new install it does not.</p>
<p>Has anyone else faced this situation and can help.</p>
<p>Thanks.</p>
|
<p>Thanks Judah,</p>
<p>For the sake of completeness and accuracy , I am posting the actual code for inheriting from a krypton form.</p>
<pre><code>public partial class Form1 : ComponentFactory.Krypton.Toolkit.KryptonForm
</code></pre>
|
How do I split a string on a fixed character sequence? <p>Suppose I have following string:</p>
<pre><code>String asd = "this is test ass this is test"
</code></pre>
<p>and I want to split the string using "ass" character sequence.</p>
<p>I used:</p>
<pre><code>asd.split("ass");
</code></pre>
<p>It doesn't work. What do I need to do?</p>
|
<p>It seems to work fine for me:</p>
<pre><code>public class Test
{
public static void main(String[] args) {
String asd = "this is test ass this is test";
String[] bits = asd.split("ass");
for (String bit : bits) {
System.out.println("'" + bit + "'");
}
}
}
</code></pre>
<p>Result:</p>
<pre><code>'this is test '
' this is test'
</code></pre>
<p>Is your real delimiter different perhaps? Don't forget that split uses its parameter as a regular expression...</p>
|
How do I display a dataset or group as a comma delimited list in SSRS? <p>In my SQL database, I have a one-to-many relationship, something like this:</p>
<pre>
Teacher Student
John Alex
John Mike
John Sean
Bob Jack
Gary George
Gary Paul
</pre>
<p>I'd like to display a table listing each teacher, with their students as a comma-delimited list, like this:</p>
<pre>
Teacher Students
John Alex, Mike, Sean
Bob Jack
Gary George, Paul
</pre>
<p><a href="http://stackoverflow.com/questions/180032/how-can-i-combine-multiple-rows-into-a-comma-delimited-list-in-sql-server-2005">This question</a> describes how to do this on the SQL Server end, but is there a way to do this on the SSRS side of things?</p>
|
<p>I've found a simpler, straight-forward method to do this -- add an expression as follows:</p>
<pre><code>=Join(LookUpSet(Fields!TeacherName.Value,
Fields!TeacherName.Value,
Fields!StudentName.Value,
"YourTeacherDataSet"), ",")
</code></pre>
|
What's the deal with all the different UIDs a process can have? <p>Real UID, effective UID, and some systems even have a "saved UID". What's the purpose of all these, especially the last one?</p>
|
<p>Each UNIX process has 3 UIDs associated to it. Superuser privilege is UID=0.</p>
<p><strong>Real UID</strong></p>
<p>This is the UID of the user/process that created THIS process. It can be changed only if the running process has EUID=0.</p>
<p><strong>Effective UID</strong></p>
<p>This UID is used to evaluate privileges of the process to perform a particular action. EUID can be changed either to RUID, or SUID if EUID!=0. If EUID=0, it can be changed to anything.</p>
<p><strong>Saved UID</strong></p>
<p>If you run an executable with the set-UID bit set, then the resulting running process will start off with a real UID of the real user running it, and an effective and saved UID of the owner of the executable file. If the process then calls setuid() or seteuid() to change their effective UID, they can still get back their original privileges again thanks to the saved UID. If the set-UID bit is not set, SUID will be the RUID.</p>
|
Master page from external library <p>I want to put my master pages in a central library so I can use them in several projects without having the maintanance nightmare.
Everything is refactored in a generic and central way, they are all in a "shared" namespace.
But if put them in a seperate project, I can't reference them</p>
|
<p>I don't believe you can put that actual .master pages in an external library. You can place your own customer MasterPage-derived class in the library, and have your client apps derive from that, but I don't think that's what your intent is, since you're tagged with asp.net-mvc (implying very narrow views without much logic, and probably no code-behinds). </p>
<p>As far as I'm aware, there isn't a way to reference a master (nor, for that matter, an ASPX or ASCX) from an external library. Wish I had better news for you. (And I actually hope I'm wrong; I hope someone else here has figured out a technique for this, as I'd like to use that kind of thing myself on occasion.)</p>
|
ASP.NET trusted DB connection to other server works in Casini, not in IIS <p>Our website connects to a database correctly when running the website locally using the built-in web server. But, when we deploy the site to our server running IIS, we get a database connection error. The database server is different from our IIS server. Note that a trusted connection to a different database on the SAME server as IIS works fine.</p>
<p>What do we need to do to connect to a SQL database on a different server with a trusted connection?</p>
|
<p>When you're running a web site using Cassini, the account used by the web server process is your own account that you use to log on to your Windows machine. That account will be different on IIS.</p>
<p>Consider the security implications of opening the database up to a broader access than you may need with trusted connection. Perhaps you could use Windows authentication with a service account. That is, create an application-specific user in SQL Server with limited permissions. Then, you will get the benefits of connection pooling while avoiding passing credentials.</p>
|
What can cause intermittent ORA-12519 (TNS: no appropriate handler found) errors <p>We are running our Junit 4 test suite against Weblogic 9 in front of an Oracle 10 database (using Hudson as a continuous integration server) and occasionally we will get an ORA-12519 crash during script teardown. However, the error is very intermittent: </p>
<ul>
<li>It usually happens for the same Test class </li>
<li>It doesn't always happen for the same test cases (sometimes they pass) </li>
<li>It doesn't happen for the same number of test cases (anywhere from 3-9) </li>
<li>Sometimes it doesn't happen at all, everything passes </li>
</ul>
<p>While I can't guarantee this doesn't happen locally (when running against the same database, of course), I have run the same suite of class multiple times with no issues.</p>
<p>Any ideas?</p>
|
<p>Don't know if this will be everybody's answer, but after some digging, here's what we came up with.</p>
<p>The error is obviously caused by the fact that the listener was not accepting connections, but why would we get that error when other tests could connect fine (we could also connect no problem through sqlplus)? The key to the issue wasn't that we couldn't connect, but that it was <strong>intermittent</strong></p>
<p>After some investigation, we found that there was some static data created during the class setup that would keep open connections for the life of the test class, creating new ones as it went. Now, even though all of the resources were properly released when this class went out of scope (via a finally{} block, of course), there were some cases during the run when this class would swallow up all available connections (okay, bad practice alert - this was unit test code that connected directly rather than using a pool, so the same problem could not happen in production).</p>
<p>The fix was to not make that class static and run in the class setup, but instead use it in the per method setUp and tearDown methods.</p>
<p>So if you get this error in your own apps, slap a profiler on that bad boy and see if you might have a connection leak. Hope that helps.</p>
|
How to print a PDF from the browser <p>In a Web application, is it possible to force a PDF file to be printed on the client? If the browser is configured to open the PDF inside the window, I guess that calling window.print() will work, but some browsers (like mine) are configured to open the PDF externally.</p>
|
<p>The way google docs does it is by embedding JavaScript into the PDF that tells Acrobat Reader or any other compliant reader to print it.</p>
<p>You would need a PDF toolkit to do this with a random PDF.</p>
|
Select from same table as an Insert or Update <p>Clearly the following is incorrect.</p>
<pre><code>INSERT INTO `aTable` (`A`,`B`) VALUES((SELECT MAX(`A`) FROM `aTable`)*2),'name');
</code></pre>
<p>I get the value:</p>
<p>SQL query: </p>
<pre><code>INSERT INTO `aTable` (`A`, `B` )
VALUES
(
(
SELECT MAX(`A`)
FROM `aTable`
) *2
, 'name'
)
</code></pre>
<p>MySQL said:</p>
<p>1093 - You can't specify target table 'aTable' for update in FROM clause </p>
<p>So, I'm trying to make a bitmap table, each row corresponds to one Bit, and has a 'map' value.</p>
<p>To insert in the table, I don't want to do two queries, I want to do one.
How should I do this?</p>
<p>No one commented on this, but since I am trying to make a bitmap, it should be * 2 not ^ 2, my mistake, please note that is why the comments often say ^ 2, it was an error in the version that the commenters read.</p>
|
<p>try:</p>
<pre><code>insert into aTable select max(a)^2, 'name' from aTable;
</code></pre>
<p>or</p>
<pre><code>insert into aTable select max(a)^2, 'name' from aTable group by B;
</code></pre>
<p>If you need a join, you can do this:</p>
<pre><code>insert into aTable select max(a)^2, 'name' from aTable, bTable;
</code></pre>
<p>My "Server version" is "5.0.51b-community-nt MySQL Community Edition (GPL)"</p>
|
Axis2 Web Service Client Generation - Types without modifying the client <p>Is it possible with Axis2 and Eclipse to generate a Web Service client and have it use java types that you already have in packages instead of creating it's own types. Reason being of course if I have type A already created and it creates it's own Type A I can't just assign variable of type A to variable of type B.</p>
<p>The wsdl is being generated from a Web Service deployed to an application server.
If it's not possible to generate it from that would it be possible to generate a client from the already existing java files.</p>
|
<p>If you really want to reuse existing classes, you can call the Axis2 API directly without generating a client using wsdl2java. Below is some relatively simple code to call a web service. You just need to fill in the web service endpoint, method QName, expected return Class(es), and arguments to the service. You could reuse your existing classes as the return values or arguments.</p>
<p>If your web service is pretty complicated then you may find that you have to go deeper into the API to get this approach to work.</p>
<pre><code>serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference("http://myservice");
options.setTo(targetEPR);
QName methodName = new QName("ns","methodName");
Class<?>[] returnTypes = new Class[] { String.class };
Object[] args = new Object[] { "parameter" };
Object[] response = serviceClient.invokeBlocking(methodName, args,
returnTypes);
</code></pre>
|
Migrating from other Content Management Systems to SharePoint <p>I am currently working on a project which requires migration of content from different content management Systems to SharePoint. Are there any good, preferably open source, tools that would help me do this? Also, what are the best practices that I would have to keep in mind when it comes to such projects. One more thing that i would like to factor here is reusablity, because we might have to work on similar migration projects, from other Content Management systems in future. </p>
|
<p>You can check <a href="http://www.codeplex.com/SPMigration" rel="nofollow">http://www.codeplex.com/SPMigration</a> (open source, project started by a Microsoft consultant).</p>
<p>This framework gives you an importer tool, as well as some exporter example (FileSystem for example). You'll problably have to code your own exporter.</p>
|
ActiveX plugin causes ASSERT to fail on application exit in VS2008 <p>My MFC application using the "ESRI MapObjects LT2" ActiveX plugin throws an ASSERT at me when closing it.
The error occurs in <code>cmdtarg.cpp</code>:</p>
<pre><code>CCmdTarget::~CCmdTarget()
{
#ifndef _AFX_NO_OLE_SUPPORT
if (m_xDispatch.m_vtbl != 0)
((COleDispatchImpl*)&m_xDispatch)->Disconnect();
ASSERT(m_dwRef <= 1); //<--- Fails because m_dwRef is 3
#endif
m_pModuleState = NULL;
}
</code></pre>
<p>I built the (native C++) application with VC9.
When I compile the application with VC6, it behaves nicely.</p>
<p>What could be the reason for this?</p>
|
<p>That looks like a reference count. Could this "target" be referenced by something else, something that's not releasing it?</p>
|
MySQL LEFT JOIN SELECT not selecting all the left side records? <p>I'm getting odd results from a <code>MySQL SELECT</code> query involving a <code>LEFT JOIN</code>, and I can't understand whether my understanding of <code>LEFT JOIN</code> is wrong or whether I'm seeing a genuinely odd behavior.</p>
<p>I have a two tables with a many-to-one relationship: For every record in <code>table 1</code> there are 0 or more records in <code>table 2</code>. I want to select all the records in table 1 with a column that counts the number of related records in table 2. As I understand it, <code>LEFT JOIN</code> should always return all records on the <code>LEFT</code> side of the statement.</p>
<p>Here's a test database that exhibits the problem:</p>
<pre><code>CREATE DATABASE Test;
USE Test;
CREATE TABLE Dates (
dateID INT UNSIGNED NOT NULL AUTO_INCREMENT,
date DATE NOT NULL,
UNIQUE KEY (dateID)
) TYPE=MyISAM;
CREATE TABLE Slots (
slotID INT UNSIGNED NOT NULL AUTO_INCREMENT,
dateID INT UNSIGNED NOT NULL,
UNIQUE KEY (slotID)
) TYPE=MyISAM;
INSERT INTO Dates (date) VALUES ('2008-10-12'),('2008-10-13'),('2008-10-14');
INSERT INTO Slots (dateID) VALUES (3);
</code></pre>
<p>The Dates table has three records, and the Slots 1 - and that record points to the third record in Dates.</p>
<p>If I do the following query..</p>
<pre><code>SELECT d.date, count(s.slotID) FROM Dates AS d LEFT JOIN Slots AS s ON s.dateID=d.dateID GROUP BY s.dateID;
</code></pre>
<p>..I expect to see a table with 3 rows in - two with a count of 0, and one with a count of 1. But what I actually see is this:</p>
<pre><code>+------------+-----------------+
| date | count(s.slotID) |
+------------+-----------------+
| 2008-10-12 | 0 |
| 2008-10-14 | 1 |
+------------+-----------------+
</code></pre>
<p>The first record with a zero count appears, but the later record with a zero count is ignored. </p>
<p>Am I doing something wrong, or do I just not understand what LEFT JOIN is supposed to do?</p>
|
<p>You need to <code>GROUP BY d.dateID</code>. In two of your cases, <code>s.DateID</code> is <code>NULL</code> (<code>LEFT JOIN</code>) and these are combined together.</p>
<p>I think you will also find that this is invalid (ANSI) SQL, because d.date is not part of a <code>GROUP BY</code> or the result of an aggregate operation, and should not be able to be <code>SELECT</code>ed.</p>
|
DOS batch files: How to write to the prompt and stay in the same line to input text <p>I like to know if there is a way to read the user input inside a batch file, because i have a file named: "fif.bat" that recives two parameters (just call them <strong><em>paramA</em></strong> and <strong><em>paramB</em></strong>) so i execute the file like this:</p>
<pre><code>fif paramA paramB
</code></pre>
<p>I have to change paramA every month, but i call this file lot of times so i like to open a console and have printed this:</p>
<pre><code>fif paramA
</code></pre>
<p>So i only have to write paramB and change paramA when i want it.</p>
<p>PD: paramA is very large so it's very helpful if i can have it there instead of writing every time. And i don't want to make another batch file to call fif whit paramA.</p>
|
<p>I think this might be what you're looking for:</p>
<pre><code>@ECHO OFF
SET /p paramA=Parameter A:
ECHO you typed %paramA%
PAUSE
</code></pre>
<p>Line one stops commands in batch file from being echoed to the console
Line two prompts the user with "Parameter A:" and waits for user to enter a value and press enter. The value goes into a variable called paramA.
Line three echoes the value of the variable paramA to the console
Line four waits for the user to hit any key.</p>
<p>Note that the SET /p command does not work on every version of windows, I beleive it was introduced in 2000, but I could be wrong on the version.</p>
|
XML authoring/cms tool <p>I am trying to find a good open source XML authoring tool so the work flow between the client and the developers will be a bit more streamlined.</p>
<p>We are basically developing a lot of XML driven micro websites for various clients and products. And often the clients want to have a little content change here and there. Sometimes just to change an capital letter or very unspecific stuff. So they end up sending us an email with a word document containing their updates. And then we lose some time again to publish those updates. It's not a lot of effort, but it still has to be made.</p>
<p>We were wondering, before making it ourselves, if there is a simple XML authoring/cms system out there. Where the developer could simply pick the editable fields/nodes and turn it to a simple but straightforward CMS for the client.</p>
|
<p>A combination of <a href="http://www.altova.com/products/xmlspy/xml_editor.html" rel="nofollow">Altova XMLSpy</a> (expensive, but worth it), <a href="http://www.altova.com/products/stylevision/xslt_stylesheet_designer.html" rel="nofollow">Altova Stylevision</a> (expensive, but worth it) and <a href="http://www.altova.com/products/authentic/xml_db_form_editor.html" rel="nofollow">Altova Authentic</a> (free):</p>
<ol>
<li>Your devs create the XML schema in XMLSpy.</li>
<li>They then create a "form" design in Stylevision for the XML. </li>
<li>Then, the end-users open the XML files with Authentic and see a MS Word-like interface for modifying the files.</li>
</ol>
<p>I used this setup on a project a while back and the Authentic side was so easy that I had an upper-level manager (non tech) and his administrative assistant build out the data for the entire project without my hand-holding. </p>
|
Best pattern for simulating "continue" in Groovy closure <p>It seems that Groovy does not support break and continue from within a closure. What is the best way to simulate this?</p>
<pre><code>revs.eachLine { line ->
if (line ==~ /-{28}/) {
// continue to next line...
}
}
</code></pre>
|
<p>You can only support continue cleanly, not break. Especially with stuff like eachLine and each. The inability to support break has to do with how those methods are evaluated, there is no consideration taken for not finishing the loop that can be communicated to the method. Here's how to support continue --</p>
<p>Best approach (assuming you don't need the resulting value).</p>
<pre><code>revs.eachLine { line ->
if (line ==~ /-{28}/) {
return // returns from the closure
}
}
</code></pre>
<p>If your sample really is that simple, this is good for readability.</p>
<pre><code>revs.eachLine { line ->
if (!(line ==~ /-{28}/)) {
// do what you would normally do
}
}
</code></pre>
<p>another option, simulates what a continue would normally do at a bytecode level.</p>
<pre><code>revs.eachLine { line ->
while (true) {
if (line ==~ /-{28}/) {
break
}
// rest of normal code
break
}
}
</code></pre>
<p>One possible way to support break is via exceptions:</p>
<pre><code>try {
revs.eachLine { line ->
if (line ==~ /-{28}/) {
throw new Exception("Break")
}
}
} catch (Exception e) { } // just drop the exception
</code></pre>
<p>You may want to use a custom exception type to avoid masking other real exceptions, especially if you have other processing going on in that class that could throw real exceptions, like NumberFormatExceptions or IOExceptions.</p>
|
Using Ext JS in ASP.NET <p>I donât have advanced knowledge in JavaScript, and I am trying to learn how to use Ext JS framework in ASP.NET (C# or VB.NET) environment. Iâve got couple of samples, but was unable get the project working. Is there such as website or book so I can go a read up about Ext JS in more details and how can I include this into my website?</p>
|
<p>Mike,</p>
<p>The best example site out there is <a href="http://examples.extjs.eu/" rel="nofollow">http://examples.extjs.eu/</a>. Each example has a link for viewing HTML, javascript and CSS separately.</p>
<p>We are successfully integrating ExtJS with the ASP.NET MVC framework. A separate post detailing how to put everything together is probably in order.</p>
|
Are there any recommendations for tools for remote collaboration on Windows? <p>The company I work for currently uses "Go To Meeting" to share our desktops but it's quite expensive for what we use it for and we are looking for cheaper (or even free) alternatives.</p>
<p>We have evaluated yuuguu and yugma but they aren't up to scratch. They are both slow and only allow the sharers to share the entire desktop as opposed to individual applications. </p>
<p>The functionality we need is to specify which application is shared and also to give the viewers permission to control the mouse and keyboard. Everything else would be an added bonus.</p>
<p>Thanks.</p>
|
<p>I use <a href="http://www.crossloop.com" rel="nofollow">CrossLoop</a> and it works well, it is free!</p>
|
windows automatic software updates <p>What are some good solutions for handling automatic web based software updates for windows forms projects? I am aware of microsoft one-click, but am not interested in it at this time.</p>
|
<p>ClickOnce is good for cookie cutter stuff, but has some limitations around security (i.e. can't create a desktop icon, no access to COM, etc)</p>
<p>Assuming you are using MSI to install your application. Use WIX (<a href="http://wix.sourceforge.net/" rel="nofollow">http://wix.sourceforge.net/</a>) to create a patch (.msp). You will want to look into Least Privileged User Account (LUA) Patching for Vista as UAC will screw you if you don't.</p>
<p>Then your application does the follows:</p>
<ol>
<li>Check for a new version via HTTP</li>
<li>Download the MSP (be careful of where you DL it to in Vista because of UAC) </li>
<li>Start a Shim exe that</li>
<li>waits for your app to close</li>
<li>launches the msp (in non-interactive mode)</li>
<li>restarts your app</li>
</ol>
<p>This can all happen automatically behind the scenes with zero user interaction on both XP and Vista.</p>
<p>A good place to start with this, and with WIX in general is:</p>
<p><a href="http://www.tramontana.co.hu/wix/index.php" rel="nofollow">http://www.tramontana.co.hu/wix/index.php</a>
(Lesson 4 is on Updates)</p>
|
Integrated Security for multiple domains? <p>Is there a way to connect to a db with Integrated Security from multiple domains?</p>
|
<p>yes, you have to set up the active directory domains to handle a restricted trust. Then sql server can use the credentials from both domains.</p>
|
Dynamically look up column names for a table while in an sql query <p>I'm writing SQL (for Oracle) like:</p>
<pre>
INSERT INTO Schema1.tableA SELECT * FROM Schema2.tableA;
</pre>
<p>where Schema1.tableA and Schema2.tableA have the same columns. However, it seems like this is unsafe, since the order of the columns coming back in the SELECT is undefined. What I should be doing is:</p>
<pre>
INSERT INTO Schema1.tableA (col1, col2, ... colN)
SELECT (col1, col2, ... colN) FROM Schema2.tableA;
</pre>
<p>I'm doing this for lots of tables using some scripts, so what I'd like to do is write something like:</p>
<pre>
INSERT INTO Schema1.tableA (foo(Schema1.tableA))
SELECT (foo(Schema1.tableA)) FROM Schema2.tableA;
</pre>
<p>Where foo is some nifty magic that extracts the column names from table one and packages them in the appropriate syntax. Thoughts?</p>
|
<p>This PL/SQL should do it:</p>
<pre><code>declare
l_cols long;
l_sql long;
begin
for r in (select column_name from all_tab_columns
where table_name = 'TABLEA'
and owner = 'SCHEMA1'
)
loop
l_cols := l_cols || ',' || r.column_name;
end loop;
-- Remove leading comma
l_cols := substr(l_cols, 2);
l_sql := 'insert into schema1.tableA (' || l_cols || ') select '
|| l_cols || ' from schema2.tableA';
execute immediate l_sql;
end;
/
</code></pre>
|
Any good team-chat websites? <p>Are there any good team-chat websites, preferably in Python, ideally with CherryPy or Trac?</p>
<p>This is similar to <a href="http://stackoverflow.com/questions/46612/whats-a-good-freeware-collaborative-ie-multiuser-instant-messenger#46660">http://stackoverflow.com/questions/46612/whats-a-good-freeware-collaborative-ie-multiuser-instant-messenger#46660</a>, but a few primary differences:</p>
<p>1) I very much want to host the server.</p>
<p>2) I don't care if Smileys are included or not in the client.</p>
<p>3) I'd like two options for the users:<br />
a) Ability to host a private IRC like chat on my Trac page (or link to such a page),<br />
b) allow remote clients to also interact. </p>
|
<p><a href="http://www.campfirenow.com/" rel="nofollow">Campfire</a> from 37 signals - the rails guys.</p>
<p><strong>Edit:</strong> It doesn't meet your requirements but it has some great features...</p>
|
Visio database diagrams, associating columns <p>I'm trying to be a good developer and create some documentation before I start programming my next project.</p>
<p>I have created a database schema diagram in Visio and created relationships between columns.</p>
<p>However, I am looking for a way to make the relationships between columns more clear. I want the arrow to connect column to column.</p>
<p>Is there a way to do this in Visio?</p>
<p><img src="http://i.stack.imgur.com/sj0Bo.jpg" alt="http://i.stack.imgur.com/sj0Bo.jpg"></p>
|
<p>You can use the Visio Drawing tools to force the Relationship Connector to glue to particular Connection Points on the Table Shapes:</p>
<ol>
<li>Turn on Connection Points in the View menu.</li>
<li>On the standard toolbar find the Connector Tool just to the right of the Pointer Tool. Click on the little arrow and change to the Connection Point Tool.</li>
<li>Hold Ctrl and click on one of the Table Shapes at the point where you want to join the Relationship Connector.</li>
<li>Do the same on the other Table Shape.</li>
<li>Glue the ends of the Relationship Connector to the Connection Points you just added.</li>
<li>You will have broken the relationship. To fix it, select the Relationship Connector and view the definition of the relationship in the Database Properties Window. </li>
<li>Associate the fields again.</li>
</ol>
<p>(This was tested with Visio Enterprise 2003.)</p>
|
How can I use the Twitter Search API to return all tweets that match my search query, posted only within the last five seconds? <p>I would like to use the API to return all tweets that match my search query, but only tweets posted within the last five seconds.</p>
<p>With Twitter's Search API, I can use the since_id to grab all tweets from a specific ID. However, I can't really see a good way to find the tweet ID to begin from.</p>
<p>I'm also aware that you can use "since:" in the actual query to use a date, but you cannot enter a time.</p>
<p>Can someone with Twitter API experience offer me any advice? Thanks for reading and your time!</p>
<p><a href="http://apiwiki.twitter.com/Search-API-Documentation">http://apiwiki.twitter.com/Search-API-Documentation</a></p>
|
<p>This sounds like something you can do on your end, as created_at is one of the fields returned in the result set. Just do your query, and only use the ones that are within the last 5 seconds. </p>
|
Well explained algorithms for indexing and searching in metric spaces <p>I need to implement some kind of metric space search in Postgres(*) (PL or PL/Python). So, I'm looking for good sources (or papers) with a very clear and crisp explanation of the machinery behind these ideas, in such way that I can implement it myself.</p>
<p>I would prefer clarity over efficiency.</p>
<p>(*) The need for that is described better <a href="http://stackoverflow.com/questions/122990/how-to-determine-if-a-record-in-every-source-represents-the-same-person">here</a>.</p>
|
<p>Especially for geographical data, look at <a href="http://postgis.refractions.net/" rel="nofollow">PostGIS</a> first to see if you need to implement anything. If you do, start with the papers listed in the <a href="http://en.wikipedia.org/wiki/GiST" rel="nofollow">Wikipedia entry on GiST</a>.</p>
<p>Looking at your link, it seems your metric space is strings with some sort of edit distance as the metric. A nice but oldish overview of some solutions is given by <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.5629" rel="nofollow">Navarro, Baeza-Yates, Sutinen, and Tarhio, IEEE Data Engineering Bulletin, 2001</a>; the related papers on Citeseer could also be useful. <a href="http://www.mit.edu/~andoni/LSH/" rel="nofollow">Locality Sensitive Hashing</a> is a newer technique that might be useful, but a lot of the papers are heavy on math.</p>
|
How do I distinguish a file from a directory in Perl? <p>I'm trying to traverse through all the subdirectories of the current directory in Perl, and get data from those files. I'm using grep to get a list of all files and folders in the given directory, but I don't know which of the values returned is a folder name and which is a file with no file extention. </p>
<p>How can I tell the difference? </p>
|
<p>You can use a <strong>-d</strong> file test operator to check if something is a directory. Here's some of the commonly useful file test operators</p>
<pre>
-e File exists.
-z File has zero size (is empty).
-s File has nonzero size (returns size in bytes).
-f File is a plain file.
-d File is a directory.
-l File is a symbolic link.
</pre>
<p>See <a href="http://perldoc.perl.org/perlfunc.html#-X-FILEHANDLE">perlfunc manual page for more</a></p>
<p>Also, try using <a href="http://search.cpan.org/~rgarcia/perl-5.10.0/lib/File/Find.pm">File::Find</a> which can recurse directories for you. Here's a sample which looks for directories....</p>
<pre><code>sub wanted {
if (-d) {
print $File::Find::name." is a directory\n";
}
}
find(\&wanted, $mydir);
</code></pre>
|
Start program on a second monitor? <p>Is there a way to specify which monitor a application appears on in Delphi or C++Builder? </p>
<p>I am developing a simple program for a customer, which displays kitchen orders on a secondary monitor, generated by a hospitality system. Currently they need to manually drag the window onto the second monitor after it starts.</p>
|
<p>The global Screen object (part of Forms) has the concept of Monitors. I think this was added circa Delphi 6 or 7. The following code will work:</p>
<pre><code>// Put the form in the upper left corner of the 2nd monitor
// if more then one monitor is present.
if Screen.MonitorCount > 1 then
begin
Left := Screen.Monitors[1].Left;
Top := Screen.Monitors[1].Top;
end;
</code></pre>
<p>You could use any positive offset from that position to put it anywhere in that monitor. You can get the width and height from there too to know the dimensions. </p>
|
When does the standard 404 page appear? <p>I am building a simple HTTP server for a project.
Most websites have custom 404 error pages. Sometimes though, you'll see Firefox spitting a generic 404 page (or 405, etc...).
How does it decide what to do?
What should the HTTP response be?
Is "HTTP/1.0 404 NOT FOUND" enough?</p>
<p>Thanks</p>
|
<p>If server can't find the requested resource (e.g. a webpage), it sends an <strong>HTTP/1.0 404 NOT FOUND</strong> in the HTTP header section. </p>
<p><strong>Servers can map</strong> an error page for this error, so you can get a readable error page. <strong>Browsers can also map</strong> an own error page, so you can see a browser-specific error 404 message. </p>
<p>You can see the error code in the <strong>status field in log files</strong>.</p>
<p>You can <strong>redirect your user</strong> to a specific page with this structure:</p>
<pre><code><HTML>
<head>
<meta HTTP-EQUIV="Refresh" CONTENT="5; URL=not404.htm">
</head>
</HTML>
</code></pre>
<p>See details on <a href="http://www.howtofriends.com/404error/" rel="nofollow">Welcome to 404 Error Pages .com</a></p>
|
Best way to check when a specified date occurs <p>Are there any classes in the .NET framework I can use to throw an event if time has caught up with a specified DateTime object?</p>
<p>If there isn't, what are the best practices when checking this? Create a new thread constantly checking? A timer (heaven forbid ;) )?</p>
|
<p>I wouldn't go with the thread approach. While a sleeping thread doesn't consume user CPU time, it does use Kernel/system CPU time. Secondly, in .NET you can't adjust the Thread's stack size. So even if all it does is sleep, you are stuck with a 2MB hit (I believe that is the default stack size of a new thread) for nothing.</p>
<p>Using System.Threading.Timer. It uses an efficient timer queue. It can have hundreds of timers that are lightweight and only execute on 1 thread that is reused between all timers (assuming most timers aren't firing at the same time).</p>
|
Index varchar on MS SQL Server 2005 <p>I need to index a varchar field on my table in MS SQL Server 2005, but it's not clear to me how to do so. If I try to add a non-clustered index on the field, it says "Column 'xxxx' in table 'mytable' is of a type that is invalid for use as a key column in an index"</p>
<p>My table has an auto-increment int ID that is set as the primary key on the table. If I set this property as the index, and then add my varchar column as an "included column", the index goes through. But I'm not sure that's what I want - I want to be able to search the table based on the varchar field alone, and my understanding of indexes was that all indexed elements had to be provided to actually see a speedup in the query, but I don't want to have to included the int ID (because I don't know what it is, at the time of this given query).</p>
<p>Am I trying to do this incorrectly? Would the ID + my varchar as an included column accomplish what I am looking for?</p>
|
<p>Is your <code>varchar(max)</code>? I think those aren't allowed to be used in an index.</p>
<p>Otherwise, post your <code>CREATE TABLE</code> statement, normally there is no problem adding a <code>varchar</code> to an index.</p>
|
TCP connection quality in .NET <p>I have a mission-critical real-time data application that uses a TCP connection between the client and server. In some cases, the connection periodically dies (SocketException). No problem - just reconnect and move on. However, the customers aren't thrilled with these intermittent drops in connectivity.</p>
<p>I'd like to know where to point the finger. Is it the client or server? Hardware or software? Is it something about the ethernet link? The end result would be to show the user an indicator of connection health, so that a bad link can be investigated and remedied.</p>
<p><strong>Are there any metrics I can pull from the TcpClient, Socket, or anything else that will tell me about the health of the connection?</strong> Perhaps average time to ack, number of retries, etc?</p>
<p>I specifically want to know about a TCP connection - not just the ethernet connection as a whole (your LAN connection might be dandy, but there could be an issue going to an outside server).</p>
<p>Of course I could ping the remote host, but I don't think that would really give me the kind of stats I'm looking for. For one thing, I could be pinging a router if the server is hiding behind NAT.</p>
|
<p>Firstly, you should inspect the details of the SocketExceptions you're getting. I don't know what they contain in .Net, but in Java the detailed message provides a useful hint, such as "Connection closed by peer" or "Connection reset".</p>
<p>In my experience, a common cause of socket connections being dropped is a bug in the code where a read timeout exception is handled by the same catch clause as all other connection-related exceptions, thus usually resulting in the connection being closed for no good reason.</p>
<p>In enterprise setups, the typical cause of long-lasting TCP connections being closed is a firewall appliance that closes TCP connections with no traffic, say, after 10 minutes, or closes connections after their age reaches, say, 30 minutes, regardless of the traffic. In general, it's best to assume that these things will happen, and be prepared to reestablish the connection gracefully.</p>
<p>A good approach is to see whether there's a pattern in connection closers. For example, whether they are closed periodically, or after a certain time of no activity. You can also run a packet sniffer to see which side initiates the connection shutdown or sends the RST packet and why.</p>
|
SetLimitText() in a CEdit in Vista does not work <p>This is happening on Vista.
I created a new dialog based MFC project to test this. I added a CEdit control to my dialog. I called SetLimitText to let my CEdit receive 100000 characters. I tried both:</p>
<pre><code>this->m_cedit1.SetLimitText(100000);
UpdateData(FALSE);
</code></pre>
<p>and </p>
<pre><code>static_cast<CEdit*>(GetDlgItem(IDC_EDIT1))->LimitText(100000);
</code></pre>
<p>I placed these calls on InitDialog.</p>
<p>after I paste 5461 characters into my CEdit, it becomes empty and unresponsive. Any ideas as to what is causing this and workarounds to be able to paste long strings of text in a CEdit or any other control?</p>
<p>note: 5461 is 0x1555 or 1010101010101 in binary, which i find quite odd.</p>
<p>if I paste 5460 characters I have no problems.</p>
|
<p>I contacted microsof support. </p>
<p>The goal was to have approximately
240000 characters in one single
editable line of text.</p>
<p>I am able to reproduce the issue on
Windows Vista (x64 and x32 both) but
<em>not</em> on Windows XP. </p>
<p>this code works fine in XP:</p>
<pre><code> BOOL ClongeditXPDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
UINT limit = m_longEdit.GetLimitText();
m_longEdit.SetLimitText(240000);
UINT limit2 = m_longEdit.GetLimitText();
CString str;
str = _T("");
for(int i = 0; i < 250000; i++)
str += _T("a");
m_longEdit.SetWindowText(str);
return TRUE; // return TRUE unless you set the focus to a control
}
</code></pre>
<p>If I use a CRichEdit control instead,
when I press "end" key or "right
arrow" key after pasting a long string
inside, i cannot see all the
characters in the Rich Edit Control.
trying to scroll past the last visible
character produces a beep. The rest of
the characters are there, I know this
because if i double-click the Rich
Edit Control and copy the text using
ctrl-c and then paste it on a text
editor, I can see the 240000
characters. So the control is holding
the right amount of characters, but
the last characters are not viewable
except in an external editor, so my
original problem remains.</p>
<p>Here are the answers by microsoft
representatives:</p>
<blockquote>
<p>Problem here is that an edit control
with a large number of characters in
it does not paint its text.</p>
<p>I tried setting different characters,
and discovered that I could fit more
'l's than 'x's than 'm's. The issue
isn't directly the number of
characters, but is likely the number
of pixels. Multiplying the number of
visible characters by the pixel width
of the characters in the selected font
shows that the limit is about 32k
pixels.</p>
</blockquote>
<p>another answer from microsoft:</p>
<blockquote>
<p>I did extensive research on this issue
and would like to update you about the
case progress.</p>
<p>The primary difference between the
Edit control on Vista and on XP is
that the Edit control on Vista
pre-composes its glyphs for better
international support (internally, it
ends up calling ExtTextOut with
ETO_GLYPH_INDEX and an array of glyphs
rather than a string of characters.
This ends up saving the glyph indices
into a metafile and so runs into the
32k pixel limit. When too many
characters are provided, ExtTextOut
fails and draws nothing. The Edit
control on XP doesn't precompose the
glyphs and so doesn't have this
problem, but won't handle
international characters as well.</p>
<p>The edit control on XP will clip at
32k, but since that is offscreen it
isn't obvious. When scrolling to the
right, it starts with the first
visible character so the visible part
of the control is always earlier than
32k pixels.</p>
<p>The RichEdit control draws the
beginning, but after hitting End,
edits occur mostly offscreen.
RichEdit 3.0 and 4.1 gives similar
behavior. This appears to be the 32k
pixel limit of RichEdit control, as
the it draws its text on an offscreen
bitmap before displaying it to the
screen.</p>
<p>Considering these points, the behavior
is by design. You would need to create
your own control to get the behavior
of displaying as big string as 240000
in a single line.</p>
</blockquote>
<p>and the last one: </p>
<blockquote>
<p>I did further research on this issue
for finding any light weight
workaround for overcoming 32k pixels
limit, but unfortunately it seems that
there is no workaround for this.</p>
<p>Couple of alternatives that we tried
are RichEdit 3.0, RichEdit
4.1, using UniScribe, using different fonts etc., but none of them seems to
suffice your requirement.</p>
<p>Possibly, you would need to create
your own custom control if you wish to
display an editable single-line string
which exceeds 32k pixel limit in
Windows Vista.</p>
</blockquote>
|
How can I center content between a header and footer div? <p>In a previous question, I learned how to keep a footer div at the bottom of the page. (<a href="http://stackoverflow.com/questions/206652/how-to-create-div-to-fill-all-space-between-header-and-footer-div">see other question</a>)</p>
<p>Now I'm trying to vertically center content between the header and footer divs.</p>
<p>so what I've got is:</p>
<pre><code>#divHeader
{
height: 50px;
}
#divContent
{
position:absolute;
}
#divFooter
{
height: 50px;
position:absolute;
bottom:0;
width:100%;
}
<div id="divHeader">
Header
</div>
<div id="divContent">
Content
</div>
<div id="divFooter">
Footer
</div>
</code></pre>
<p>I've tried creating a parent div to house the existing 3 divs and giving that div a vertical-align:middle; but that gets me nowhere.</p>
|
<p>In CSS2:</p>
<pre><code>html,body {height:100%;}
body {display:table;}
div {display:table-row;}
#content {
display:table-cell;
vertical-align:middle;
}
</code></pre>
<p>&</p>
<pre><code><body>
<div>header</div>
<div id="content">content</div>
<div>footer</div>
</body>
</code></pre>
<p><a href="http://codepen.io/anon/pen/doMwvJ" rel="nofollow">http://codepen.io/anon/pen/doMwvJ</a></p>
<p>In old IE (<=7) you have to use trick with absolute positioning that marxidad mentioned.</p>
<p>And in latest browsers <a href="http://flexboxin5.com/" rel="nofollow">you can use flexbox instead</a>.</p>
|
Best JavaScript Date Parser & Formatter? <p>Since I've started to use jQuery, I have been doing a lot more JavaScript development.</p>
<p>I have the need to parse different date formats and then to display them into another format.</p>
<p>Do you know of any good tool to do this?</p>
<p>Which one would you recommend?</p>
|
<p>2014 update: <a href="http://momentjs.com/" rel="nofollow">Moment.js</a> is an excellent date manipulation library, which includes parsing functions. It doesn't include automatic date format detection, but you can <a href="http://momentjs.com/docs/#/parsing/string-formats/" rel="nofollow">specify multiple parsing patterns</a>.</p>
<p>Do you know the format of the dates before hand though, or are they user input?</p>
<hr>
<p><a href="http://www.datejs.com/" rel="nofollow">A deprecated library for parsing dates is Datejs</a>. It hasn't been updated since 2007.</p>
|
How do I prevent and/or handle a StackOverflowException? <p>I would like to either prevent or handle a StackOverflowException that I am getting from a call to the XslCompiledTransform.Transform method within an Xsl Editor I am writing. The problem seems to be that the user can write an Xsl script that is infinitely recursive, and it just blows up on the call to the Transform method. (That is, the problem is not just the typical programmatic error, which is usually the cause of such an exception.)</p>
<p>Is there a way to detect and/or limit how many recursions are allowed? Or any other ideas to keep this code from just blowing up on me?</p>
|
<p>From Microsoft:</p>
<blockquote>
<p>Starting with the .NET Framework
version 2.0, a StackOverflowException
object cannot be caught by a try-catch
block and the corresponding process is
terminated by default. Consequently,
users are advised to write their code
to detect and prevent a stack
overflow. For example, if your
application depends on recursion, use
a counter or a state condition to
terminate the recursive loop.</p>
</blockquote>
<p>I'm assuming the exception is happening within an internal .NET method, and not in your code.</p>
<p>You can do a couple things.</p>
<ul>
<li>Write code that checks the xsl for infinite recursion and notifies the user prior to applying a transform (Ugh).</li>
<li>Load the XslTransform code into a separate process (Hacky, but less work).</li>
</ul>
<p>You can use the Process class to load the assembly that will apply the transform into a separate process, and alert the user of the failure if it dies, without killing your main app.</p>
<p>EDIT: I just tested, here is how to do it:</p>
<p>MainProcess:</p>
<pre><code>// This is just an example, obviously you'll want to pass args to this.
Process p1 = new Process();
p1.StartInfo.FileName = "ApplyTransform.exe";
p1.StartInfo.UseShellExecute = false;
p1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p1.Start();
p1.WaitForExit();
if (p1.ExitCode == 1)
Console.WriteLine("StackOverflow was thrown");
</code></pre>
<p>ApplyTransform Process:</p>
<pre><code>class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
throw new StackOverflowException();
}
// We trap this, we can't save the process,
// but we can prevent the "ILLEGAL OPERATION" window
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.IsTerminating)
{
Environment.Exit(1);
}
}
}
</code></pre>
|
Printing to a client printer from a web app <p>If I have a printer hooked directly to a pc (a kiosk with a printer), how would I go about creating the ability for a web page (.net web app) to print a jpg to the kiosks printer with no user intervention other than clicking a button on the page?</p>
|
<p>This has been asked several times already, and the result is always that you <em>can't</em> do it via normal web technologies (HTML + Javascript). The best you can do is open the print dialog, and that is <em>by design</em>. What you can do since you control the kiosks is create some kind of browser extension (like a flash object, .Net hosted control, java applet, etc) and make that available to your page, so that it handles the printing part for you.</p>
|
Defining SLAs for WCF Services <p>I have to performance/load test a bunch of interdependant services. They all use net.tcp and most use duplex contracts and internal queueing. [handrolled POCO queue class using lock(syncRoot) { if(queue.Empty) Thread.Wait(); }]</p>
<p>Here's the approach I've come up with:</p>
<ol>
<li>Identify WCF Services to be performance tested</li>
<li>Identify the relavant Performance counters for each of the Services</li>
<li>Identify the logical startpoint that would take the execution through the services being tested</li>
<li>Auto Generate Unit Tests using VS.Net for each of the services</li>
<li>Write specific Functional Tests (For example, I can take a use case - "Place an Order" - and write tests that make all the calls to the relevant services and generally excercise pretty much all the functionality needed)</li>
<li>Use the trace files from running #5 to generate Unit Tests [using WCF Load Test from CodePlex] (This somehow seems to me an ideal tool for recreating user errors in production/field in a debug environment. Disclaimer: Not used the tool. Impressions from reading the project desc)</li>
<li>The tests above could be tweaked to make the calls with auto generated input data</li>
<li>Introduce variations to input so different code paths are excercised</li>
<li>Log data from performance counters</li>
<li>Analyze and identify bottlenecks</li>
</ol>
<p>Questions:</p>
<ol>
<li>Is there a better approach?</li>
<li>In case of services that use internal queues, measuring performance using std performance counters, an issue. I may need custom counters?</li>
<li>If #1 is true, is there a way to introduce customer counters without changing code of the services being tested?</li>
<li>Should I care about the results of my functional tests?</li>
<li>Is there a way to [non-intrusively] implement SLAs for WCF services? (I think if I have enough data from my counters such as requests served, exceptions occurred , response time etc., I should be able to validate my SLA - serve 200,000 requests within 5 mins with a response time of 2 seconds for each request - against these figures. My question perhaps is whether I can just specify my SLA and a product / tool could do all of the plumbing behind the scene and get me a tabulated answer? I know... I know... I was day dreaming :))</li>
<li>Aside: What's the best method to queue requests internally in a WCF Service?</li>
</ol>
|
<p>Wow...the title was definitely the tip of the iceberg! Hope I'm not way off base here on my responses! :) </p>
<ol>
<li><p>performance testing of WCF services can be done many different ways: using test tools such as Microsoft Team Test, Borland Silk Performer, Mercury LoadRunner, or something like LoadGen or a custom test harness. My preference is to try to take the approach that you've done in creating some sort of functional unit test and then feeding data into that test, while using the test tool to spin up multiple concurrent instances of that test (virtual 'users'). The tooling of most commercial test tools really facilitate this type of testing so its difficult to go wrong here. The biggest challenge usually grows out of maintaining the test cases and test data to support testing the application.</p></li>
<li><p>WCF doesn't have any built in counters related to performance. Thats actually a blind spot. Sure, you can see how many connections are being made to the server, but this is coarse information and you probably want to know which services are servicing those requests. Rumor is that Microsoft's 'Dublin', as part of providing a rich hosting environment for WCF/WF, will include surfacing performance counters for the hosted service. We will have to wait and see what actually shakes out.</p></li>
<li><p>If I needed to instrument a WCF service without impacting the existing codebase I'd look into how much mileage I could get out of a WCF behavior that i could apply to the service. This custom behavior could likely surface the performance counters you might want.</p></li>
<li><p>Yes. I would care about results (meaning performance?) of a functional test. The caveat is that there is likely some startup (JIT) which can be ignored. I'd probably look to profile the execution of a functional test to get execution metrics - but i'd not turn on code profiling during a performance run.</p></li>
<li><p>For SLA's again custom behaviors might be the answer. You could log operational metrics to a database and then report off that. Commercial products like Amberpoint and SOA Software will provide support for this as well (including performance counters).</p></li>
<li><p>Queuing requests to a wcf service? I immediately think of net.msmq binding, especially if your looking to make the request durable. </p></li>
</ol>
|
Exporting dataset to excel error: Exception from HRESULT: 0x800A03EC <p>I am having trouble in exporting to excel and it crashes out at the .set_Value function.</p>
<p>It seems to work if I change object[,] to string[,] but by doing this I lose the formatting.</p>
<p>Anyone Help?</p>
|
<p>Are you passing '<code>null</code>' for missing parameters rather than <code>System.Reflection.Missing.Value</code> ?</p>
|
Best Way To Store Multiple Flags In Database <p>I have a web-based application that notifies users of activity on the site via email. Users can choose which kinds of notifcations they want to receive. So far there are about 10 different options (each one is a true/false).</p>
<p>I'm currently storing this in one varchar field as a 0 or 1 separated by commas. For example:
1,0,0,0,1,1,1,1,0,0</p>
<p>This works but it's difficult to add new notification flags and keep track of which flag belongs to which notification. Is there an accepted standard for doing this? I was thinking of adding another table with a column for each notification type. Then I can add new columns if I need, but I'm not sure how efficient this is.</p>
<p>Thanks in advance!</p>
|
<p>I would use two tables. One table would store the user data and the other the notifications that they subscribe to. The second table would look something like this:</p>
<pre><code>create table notifications (
user_id int,
notification_type int
);
</code></pre>
<p>I'd make a FK relationship between user_id and the user's id in the users table with a cascade on delete. Use both the user_id and notification_type as the primary key. To check if a user wants a particular notification simply do a join between the two tables and select rows where the notification_type matches the one in question. If the result set is non-empty the user wants the notification.</p>
<p>Adding new notifications becomes trivial (as does deleting). Simply add (delete) a new type value and let users choose to accept it or not. If you wanted to keep the notification types in a table to manage via the application that would work, too, but it would be a little more complex.</p>
|
Python: Difference between class and instance attributes <p>Is there any meaningful distinction between:</p>
<pre><code>class A(object):
foo = 5 # some default value
</code></pre>
<p>vs.</p>
<pre><code>class B(object):
def __init__(self, foo=5):
self.foo = foo
</code></pre>
<p>If you're creating a lot of instances, is there any difference in performance or space requirements for the two styles? When you read the code, do you consider the meaning of the two styles to be significantly different?</p>
|
<p>Beyond performance considerations, there is a significant <em>semantic</em> difference. In the class attribute case, there is just one object referred to. In the instance-attribute-set-at-instantiation, there can be multiple objects referred to. For instance</p>
<pre><code>>>> class A: foo = []
>>> a, b = A(), A()
>>> a.foo.append(5)
>>> b.foo
[5]
>>> class A:
... def __init__(self): self.foo = []
>>> a, b = A(), A()
>>> a.foo.append(5)
>>> b.foo
[]
</code></pre>
|
Stripes: all URLs resolved through StripesDispatcher and forwarded to pre-compiled JSPs <p>Is it possible to have the StripesDispatcher be the sole determiner of webserver urls by looking at the @UrlBinding annotations on action beans AND also having those action beans forward to pre-compiled JSPs / servlets WITHOUT needing to define and maintain <servlet> <servlet-mapping> pairs in web.xml? Basically, I just want to have to only maintain the @UrlBinding annotations as the sole determiners of available webapp paths.</p>
<p>Perhaps there is a way to point Jasper to where my servlets are and load them all up automatically without having to explicitly define each and every one?</p>
<p>The particular way in which this is achieved is not important, only that I leave the land of explicit servlet web.xml dependencies.</p>
|
<p>Maybe I don't understand your question, but I'll give it a go. AFAIK the only mapping you need in a Stripes app's web.xml to use @URLBinding as the 'source of truth' for URLs in your web-app:</p>
<pre><code><filter>
<filter-name>StripesFilter</filter-name>
<filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
<init-param>
<param-name>ActionResolver.Packages</param-name>
<param-value>com.your.action.beans.package</param-value>
</init-param>
<init-param>
<param-name>Extension.Packages</param-name>
<param-value>com.your.extension.packages</param-value>
</param-value>
</init-param>
</filter>
</code></pre>
<p>...</p>
<pre><code><servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
</code></pre>
<p>...</p>
<pre><code><filter-mapping>
<filter-name>StripesFilter</filter-name>
<servlet-name>DispatcherServlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</code></pre>
<p>With this, there is no need to change anything in web.xml when you add/remove action beans and/or JSPs.</p>
|
Setting the Body's OnLoad attribute in an Asp.net MVC Master Page <p>I have a view using a master page that contains some javascript that needs to be executed using the OnLoad of the Body. What is the best way to set the OnLoad on my MasterPage only for certain views?</p>
<p>On idea I tried was to pass the name of the javascript function as ViewData. But I dont really want my Controllers to have to know about the javascript on the page. I really don't like this approach...</p>
<pre><code><body onload="<%=ViewData["Body_OnLoad"]%>">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</code></pre>
<p>Edit - I suppose one idea would be to use jQuery's document ready event instead...</p>
<p>Any other ideas?</p>
|
<p>Now that JQuery is officially part of ASP.NET MVC, I would recommend using it. It's small, and adds tons of value to your application.</p>
<p>I would recommend adding Mustafa's version of JQuery that has the Intellisense comments included:</p>
<p><a href="http://www.mustafaozcan.net/en/file.axd?file=jquery-1.2.6-intellisense.js">jquery-1.2.6-intellisense.js</a></p>
<p>Then add it to your Scripts folder (new in MVC Beta 1), and reference it like this:</p>
<pre><code><script language="javascript" type="text/javascript" src="../../Scripts/jquery-1.2.6-intellisense.js"></script>
</code></pre>
<p>In your code you can now add a function like this:</p>
<pre><code>$(document).ready(function() {
// do stuff when DOM is ready
});
</code></pre>
<p>Since you mentioned that you only want it to happen in certain views, you could add a placeholder in your Master Page like this:</p>
<pre><code><asp:contentplaceholder id="JavascriptPlaceholder" runat="server"></asp:contentplaceholder>
</code></pre>
<p>Then in your View, you could choose to put code in there, or not.</p>
<p>which would go inside of the head section</p>
|
Sql Server string to date conversion <p>I want to convert a string like this:</p>
<pre><code>'10/15/2008 10:06:32 PM'
</code></pre>
<p>into the equivalent DATETIME value in Sql Server.</p>
<p>In Oracle, I would say this:</p>
<pre><code>TO_DATE('10/15/2008 10:06:32 PM','MM/DD/YYYY HH:MI:SS AM')
</code></pre>
<p><a href="http://stackoverflow.com/questions/202243/custom-datetime-formatting-in-sql-server">This question</a> implies that I must parse the string into one of the <a href="http://www.sql-server-helper.com/tips/date-formats.aspx" rel="nofollow">standard formats</a>, and then convert using one of those codes. That seems ludicrous for such a mundane operation. Is there an easier way?</p>
|
<p>Try this</p>
<pre><code>Cast('7/7/2011' as datetime)
</code></pre>
<p>and</p>
<pre><code>Convert(varchar(30),'7/7/2011',102)
</code></pre>
<p>See <a href="https://msdn.microsoft.com/en-us/library/ms187928(v=sql.90).aspx">CAST and CONVERT (Transact-SQL)</a> for more details.</p>
|
Hooking up GUI interface with asynchronous (s)ftp operation <p>Trying to implement a progress dialog window for file uploads that look like a cross between <a href="http://www.codinghorror.com/blog/images/ie6-download-ui.png" rel="nofollow">IE download dialog</a> and <a href="http://www.codinghorror.com/blog/images/firefox2-download-ui.png" rel="nofollow">Firefox download dialog</a> with a python GUI library on Windows.</p>
<ol>
<li>What asynchronous (S)FTP libraries are there for python? Ideally I should be able to do file upload resumes and track the progress of each parallel file uploads.</li>
<li>If I'm running each file upload in a separate process each, how would I get the upload status and display it in a progress bar dialog?</li>
</ol>
|
<p>"ftplib" is the standard ftp library built in to Python. In Python 2.6, it had a callback parameter added to the method used for uploading.</p>
<p>That callback is a function you provide to the library; it is called once for every block that is completed.</p>
<p>Your function can send a message to the GUI (perhaps on a different thread/process, using standard inter-thread or inter-process communications) to tell it to update its progress bar.</p>
<p><a href="http://docs.python.org/library/ftplib.html" rel="nofollow" title="Python 2.6 ftplib manual">Reference</a></p>
|
firefox 3 favicons - how to make them? <p>i noticed that paypal displays a very different favicon,
one that's not just a simple 16x16 icon and is lengthy?
anyone can teach me?</p>
|
<p>I think you are refering to the green box that shows the PayPal logo followed by "PayPal, Inc. (US)". </p>
<p>If so, it is not a favicon, but a feature of Firefox 3 to show sites with extended validation (EV). See also <a href="http://news.cnet.com/8301-13554_3-9974672-33.html" rel="nofollow">http://news.cnet.com/8301-13554_3-9974672-33.html</a></p>
|
extracting a parenthesized Python expression from a string <p>I've been wondering about how hard it would be to write some Python code to search a string for the index of a substring of the form <code>${</code><em>expr</em><code>}</code>, for example, where <em>expr</em> is meant to be a Python expression or something resembling one. Given such a thing, one could easily imagine going on to check the expression's syntax with <code>compile()</code>, evaluate it against a particular scope with <code>eval()</code>, and perhaps even substitute the result into the original string. People must do very similar things all the time.</p>
<p>I could imagine solving such a problem using a third-party parser generator [oof], or by hand-coding some sort of state machine [eek], or perhaps by convincing Python's own parser to do the heavy lifting somehow [hmm]. Maybe there's a third-party templating library somewhere that can be made to do exactly this. Maybe restricting the syntax of <em>expr</em> is likely to be a worthwhile compromise in terms of simplicity or execution time or cutting down on external dependencies -- for example, maybe all I really need is something that matches any <em>expr</em> that has balanced curly braces.</p>
<p>What's your sense?</p>
<h2>Update:</h2>
<p>Thanks very much for your responses so far! Looking back at what I wrote yesterday, I'm not sure I was sufficiently clear about what I'm asking. Template substitution is indeed an interesting problem, and probably much more useful to many more people than the expression extraction subproblem I'm wondering about, but I brought it up only as a simple example of how the answer to my question might be useful in real life. Some other potential applications might include passing the extracted expressions to a syntax highlighter; passing the result to a real Python parser and looking at or monkeying with the parse tree; or using the sequence of extracted expressions to build up a larger Python program, perhaps in conjunction with some information taken from the surrounding text.</p>
<p>The <code>${</code><em>expr</em><code>}</code> syntax I mentioned is also intended as an example, and in fact I wonder if I shouldn't have used <code>$(</code><em>expr</em><code>)</code> as my example instead, because it makes the potential drawbacks of the obvious approach, along the lines of <code>re.finditer(r'$\{([^}]+)\}', s)</code>, a bit easier to see. Python expressions can (and often do) contain the <code>)</code> (or <code>}</code>) character. It seems possible that handling any of those cases might be much more trouble than it's worth, but I'm not convinced of that yet. Please feel free to try to make this case!</p>
<p>Prior to posting this question, I spent quite a bit of time looking at Python template engines hoping that one might expose the sort of low-level functionality I'm asking about -- namely, something that can find expressions in a variety of contexts and tell me where they are rather than being limited to finding expressions embedded using a single hard-coded syntax, always evaluating them, and always substituting the results back into the original string. I haven't figured out how to use any of them to solve my problem yet, but I do very much appreciate the suggestions regarding more to look at (can't believe I missed that wonderful list on the wiki!). The API documentation for these things tends to be pretty high-level, and I'm not too familiar with the internals of any of them, so I'm sure I could use help looking at those and figuring out how to get them to do this sort of thing.</p>
<p>Thanks for your patience!</p>
|
<p>I think what you're asking about is being able to insert Python code into text files to be evaluated. There are several modules that already exist to provide this kind of functionality. You can check the Python.org <a href="http://wiki.python.org/moin/Templating" rel="nofollow"><strong>Templating wiki page</strong></a> for a comprehensive list.</p>
<p>Some google searching also turned up a few other modules you might be interested in:</p>
<ul>
<li><a href="http://py-templates.sourceforge.net/texttemplate/index.html" rel="nofollow">texttemplate</a> (part of py-templates project)</li>
<li><a href="http://www.embl-heidelberg.de/~chenna/pythonpages/template.html" rel="nofollow">template module</a></li>
</ul>
<p>If you're really looking just into writing this yourself for whatever reason, you can also dig into this Python cookbook solution <a href="http://code.activestate.com/recipes/52305/" rel="nofollow">Yet Another Python Templating Utility (YAPTU) </a>:</p>
<blockquote>
<p><em>"Templating" (copying an input file to output, on the fly inserting Python
expressions and statements) is a frequent need, and YAPTU is a small but
complete Python module for that; expressions and statements are identified
by arbitrary user-chosen regular-expressions.</em></p>
</blockquote>
<p><strong>EDIT</strong>: Just for the heck of it, I whipped up a severely simplistic code sample for this. I'm sure it has bugs but it illustrates a simplified version of the concept at least: </p>
<pre><code>#!/usr/bin/env python
import sys
import re
FILE = sys.argv[1]
handle = open(FILE)
fcontent = handle.read()
handle.close()
for myexpr in re.finditer(r'\${([^}]+)}', fcontent, re.M|re.S):
text = myexpr.group(1)
try:
exec text
except SyntaxError:
print "ERROR: unable to compile expression '%s'" % (text)
</code></pre>
<p>Tested against the following text: </p>
<pre><code>This is some random text, with embedded python like
${print "foo"} and some bogus python like
${any:thing}.
And a multiline statement, just for kicks:
${
def multiline_stmt(foo):
print foo
multiline_stmt("ahem")
}
More text here.
</code></pre>
<p>Output: </p>
<pre><code>[user@host]$ ./exec_embedded_python.py test.txt
foo
ERROR: unable to compile expression 'any:thing'
ahem
</code></pre>
|
How do ASP.NET applications work when deployed without the code-behind files? <p>When you deploy an application to IIS without all files that contains code (VB/C#) then
how exactly are events & all things handled?</p>
|
<p>The VB or C# compiler compiles the ASPX pages and classes in App_Code into runtime binary DLLs. For Web projects, the DLLs get created each time you build the project; for Websites, the DLLs get created in a temp folder under c:\Windows. Maybe this is what's confusing you--you don't see the DLLs for Websites until you do Build>Publish Web Site step. </p>
<p>If you deploy a Website without first publishing it, mysteriously it runs! That's because the ASP.NET process implicitly calls the compiler to create the corresponding DLLs for each ASPX page.</p>
<p>You can prove this behavior by creating a virtual directory on your developer box over the development root of the Website. Then launch a page with <a href="http://localhost/yourappname/yourpagename.aspx" rel="nofollow">http://localhost/yourappname/yourpagename.aspx</a>. It runs! With no DLLs! They are in a project folder under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files. </p>
<p>More on the publish process:
<a href="http://msdn.microsoft.com/en-us/library/1y1404zt(VS.80).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/1y1404zt(VS.80).aspx</a></p>
<p>In either case, once compiled, the ASP.NET lifecycle kicks in and raises events as they occur. See these links for more on that process:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms227435.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms227435.aspx</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms178472.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms178472.aspx</a></p>
|
Updated Firefox Extension - Still says "No updates were found." <p>I am working on a new version of a firefox extension, but after releasing it, and incrementing the em:version in install.rdf and update.rdf, when I click "Find updates" Firefox reports that "No updates were found." When I run it with debugging on, the output in the console is actually identical to what I see when I don't put the update live. </p>
<p>It starts with RDFItemUpdater:checkForUpdates with all of the parameters, and returns with Addon Update Ended and status: 8.</p>
<p>I verified with McCoy tool that the extension is signed, and has the same Id as the old one, etc. I'm not sure what else to try. Any advice would be appreciated. This is with Firefox 3 (and the extension is marked as compatible with it... that didn't change).</p>
|
<p>Make sure your update.rdf file is being served with an appropriate Content-Type, i.e. text/rdf, text/xml or application/xml+rdf </p>
|
What is the key sequence for closing the current buffer in Emacs? <p>If I click on File -> Close, it closes the buffer like I want, but doesn't list a key mapping. What is the key mapping?</p>
|
<p>You can use <code>C-x k</code> to kill current buffer. See <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Kill-Buffer.html">Emacs Manual</a> .</p>
|
Logging Library for .NET Compact Framework? <p>Any good logging libraries that support .NET compact framework?</p>
|
<p>log4net is a good choice, I use it for all projects.</p>
|
Best mobile application development tool/environment? <p>I would like to develop a mobile application that is able to access all the features of the mobile device it runs on (camera, files, phone and network connectivity). I intend to build a series of applications that each have a specific function to perform, rather than a single application with a large feature set. My programming background is C, C# and web applications.</p>
<p>What would be the best tool set to use to do this? I have looked at using the NetBeansIDE to create a Java ME applications using LWUIT - this looks promising, but what are the caveat's?</p>
<p>I want to target the largest universe of mobile devices possible.</p>
|
<p>J2ME is the way to go to reach the masses, in the consumer or the business market. From a consumer standpoint, most of the world's mobile phones support J2ME. From a business standpoint, most of the world's smart phones support J2ME. </p>
<p>Nokia owns a 40% share of the smart phone market (and the whole market) worldwide. Next in line is Blackberry with a 13% share. Both have standard implementations of J2ME on their devices (though Blackberry also has a proprietary version of Java as well). On top of this, most devices that run Windows Mobile come with a JVM as well (I developed a game recently that initially targetted the Sony Ericsson W810i and it ran flawlessly on my HTC Tilt's JVM). Add in the fact that Android has a Java SDK and the only segment you are really missing out on are the BREW only phones and the iPhone.</p>
<p>I'm not a huge backer of J2ME. I just know that every other mobile platform has disappeared from my life over the last 3 years as it just makes financial sense for companies to only target the J2ME segment of the industry.</p>
|
Computing a cross-browser iframe height <p>One of the most difficult problems in my javascript experience has been the correct (that is "cross-browser") computing of a <strong>iframe height</strong>.
In my applications I have a lot of dynamically generated iframe and I want them all do a sort of autoresize at the end of the load event to adjust their height and width.</p>
<p>In the case of <strong>height</strong> computing my best solution is the following (with the help of jQuery):</p>
<pre><code>function getDocumentHeight(doc) {
var mdoc = doc || document;
if (mdoc.compatMode=='CSS1Compat') {
return mdoc.body.offsetHeight;
}
else {
if ($.browser.msie)
return mdoc.body.scrollHeight;
else
return Math.max($(mdoc).height(), $(mdoc.body).height());
}
}
</code></pre>
<p>I searched the internet without success. I also tested Yahoo library that has some methods for document and viewport dimensions, but it's not satisfactory.
My solution works decently, but sometimes it calculates a taller height.
I've studied and tested tons of properties regarding document height in Firefox/IE/Safari: <code>documentElement.clientHeight, documentElement.offsetHeight, documentElement.scrollHeight, body.offsetHeight, body.scrollHeight, ...</code>
Also jQuery doesn't have a coherent behavior in various browser with the calls <code>$(document.body).height(), $('html', doc).height(), $(window).height()</code></p>
<p>I call the above function not only at the end of load event, but also in the case of dynamically inserted DOM elements or elements hidden or shown. This is a case that sometimes breaks the code that works only in the load event.</p>
<p>Does someone have a real cross-browser (at least Firefox/IE/Safari) solution? Some tips or hints?</p>
|
<p>Although I like your solution, I've always found IFRAMEs to be more trouble than they're worth.</p>
<p>Why ? 1. The sizing issue. 2. the iframe has that src attribute to worry about. i.e. absolute path. 3. the extra complexity with the pages.</p>
<p>My solution - DIVs which are dynamically loaded through AJAX calls. DIVs will auto size. Although the AJAX code requires javascript work (which can be done through frameworks) they are relative to where the site is. 3 is a wash, you're trading complexity in pages up to javascript.</p>
<p>Instead of <IFRAME ...> use <DIV id="mystuff" /></p>
<p>Do the ajax call to fill the mystuff div with data and let the browser worry about it.</p>
|
Templated superclass linking problem <p>I'm trying to create a C++ class, with a templated superclass. The idea being, I can easily create lots of similar subclasses from a number of superclasses which have similar characteristics.</p>
<p>I have distilled the problematic code as follows:</p>
<p><code>template_test.h</code>:</p>
<pre><code>template<class BaseClass>
class Templated : public BaseClass
{
public:
Templated(int a);
virtual int Foo();
};
class Base
{
protected:
Base(int a);
public:
virtual int Foo() = 0;
protected:
int b;
};
</code></pre>
<p><code>template_test.cpp</code>:</p>
<pre><code>#include "template_test.h"
Base::Base(int a)
: b(a+1)
{
}
template<class BaseClass>
Templated<BaseClass>::Templated(int a)
: BaseClass(a)
{
}
template<class BaseClass>
int Templated<BaseClass>::Foo()
{
return this->b;
}
</code></pre>
<p><code>main.cpp</code>:</p>
<pre><code>#include "template_test.h"
int main()
{
Templated<Base> test(1);
return test.Foo();
}
</code></pre>
<p>When I build the code, I get linker errors, saying that the symbols <code>Templated<Base>::Templated(int)</code> and <code>Templated<Base>::Foo()</code> cannot be found.</p>
<p>A quick Google suggests that adding the following to <code>main.cpp</code> will solve the problem:</p>
<pre><code>template<> Templated<Base>::Templated(int a);
template<> int Templated<Base>::Foo();
</code></pre>
<p>But this does not solve the problem. Adding the lines to <code>main.cpp</code> does not work either. (Though, interestingly, adding them to both gives 'multiply defined symbol' errors from the linker, so they must be doing something...)</p>
<p><em>However</em>, putting all the code in one source file does solve the problem. While this would be ok for the noddy example above, the real application I'm looking at would become unmanageable very fast if I was forced to put the whole lot in one cpp file.</p>
<p>Does anyone know if what I'm doing is even possible? (How) can I solve my linker errors?</p>
<p>I would assume that I could make all the methods in <code>class Templated</code> inline and this would work, but this doesn't seem ideal either.</p>
|
<p>With templated classes, the definitions must be available for each translation unit that uses it. The definitions can go in a separate file, usually with <code>.inl</code> or <code>.tcc</code> extension; the header file <code>#include</code>s that file at the bottom. Thus, even though it's in a separate file, it's still <code>#include</code>d for each translation unit; it cannot be standalone.</p>
<p>So, for your example, rename <code>template_test.cpp</code> to <code>template_test.inl</code> (or <code>template_test.tcc</code>, or whatever), then have <code>#include "template_test.inl"</code> (or whatever) at the bottom of <code>template_test.h</code>, just before the <code>#endif</code> of the include guard.</p>
<p>Hope this helps!</p>
|
What causes this integer pointer reassignment to crash? <p>I am new to C and i have this question. why does the following code crash:</p>
<pre><code>int *a = 10;
*a = 100;
</code></pre>
|
<p>Because you are trying to write 100 to the memory location 0x0000000A which is probably not allocated to your program. That is,</p>
<pre><code>int *a = 10;
</code></pre>
<p>does not mean that the pointer 'a' will point to a location in memory having the value of 10. It means it is pointing to address 10 (0x0000000A) in the memory. Then, you want to write something into that address, but you don't have the "rights" to do so, since it is not allocated</p>
<p>You can try the following:</p>
<pre><code>int *a = malloc(sizeof(int));
*a = 100;
</code></pre>
<p>This would work, although horribly inefficient. If you only need a single int, you should just put it into the <a href="http://stackoverflow.com/questions/24891/c-memory-management">stack, not the heap</a>. On a 32-bit architecure, a pointer is 32 bits long, and an int is 32 bits long too, so your pointer-to-an-int structure takes up (<a href="http://stackoverflow.com/questions/197839/is-there-any-way-to-determine-the-size-of-a-c-array-programmatically-and-if-not#197872">at least</a>) 8 bytes of memory space this way instead of 4. And we haven't even mentioned caching issues.</p>
|
Redirect to a link using the default broswser in Windows Form based application <p>I am not use: Process.Start (String, String) to open a link. But every time the browser open a new tab or new window to open the link.
Is there a way that to open the link in the latest opened page? Just redirection, no new tab or new window?
Thanks!</p>
|
<p>This is not really up to you (the programmer) to decide but to the user: Some browsers have an option for this setting. You shouldn't try modifying the user's selected browser behaviour.</p>
<p>Someone of my team did this once in an instant messenger application that we were writing, without asking for other opinions first. The users were super annoyed that our application kept overwriting their opened pages.</p>
|
How can I use RLIKE MySQL function inside of SQL Server 2005? <p>I need to run a RLIKE query on a database mmoved from MySQL to SQL Server 2005 however having problems replicating the "RLIKE" functionality that MySQL provides.</p>
<p>Does anyone have any ideas?</p>
<p>Cheers,</p>
<p>Chris</p>
|
<p>The only way I know of to do that is to add user defined CLR functions.</p>
<p>To begin with, here's an MSDN Magazine article, "<a href="http://msdn.microsoft.com/en-us/magazine/cc163473.aspx" rel="nofollow">Regular Expressions Make Pattern Matching And Data Extraction Easier</a>"</p>
<p>The code for that article, which I've been using for a couple of years now, is <a href="http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/Regex2007_02.exe" rel="nofollow">here</a>.</p>
|
How do I get Srcsrv with SVNindex.cmd to index extern files? <p>I have recently made use of the SrcSrv feature in the <a href="http://www.microsoft.com/whdc/devtools/debugging/default.mspx" rel="nofollow">Debugging Tools For Windows</a>, but have noticed that when I index the pdb with <strong>SVNIndex.cmd</strong> it does not pick up any of the files that are from an <a href="http://svnbook.red-bean.com/en/1.0/ch07s03.html" rel="nofollow">external link</a>. </p>
<p>Any suggestions ?</p>
|
<p>Finally i got some time again to figure everything out:</p>
<p>To also get the files included with svn:externals property indexed, you just have to add the directories of them to /source= switch!
easier than i thought!
so if you have an external in "Ext1" dir under your Projectdir, just call ssindex.cmd with /source=Projectdir;Ext1 and you get all files in Ext1 also indexed.</p>
<p>I wrote a simple perl script, that handles the creation of the commandline for me, so you dont have to add any new external entry.</p>
<p>HTH, Stefan!</p>
|
How to read and write multiple files? <p>I want to write a program for this: In a folder I have <em>n</em> number of files; first read one file and perform some operation then store result in a separate file. Then read 2nd file, perform operation again and save result in new 2nd file. Do the same procedure for <em>n</em> number of files. The program reads all files one by one and stores results of each file separately. Please give examples how I can do it.</p>
|
<pre><code>import sys
# argv is your commandline arguments, argv[0] is your program name, so skip it
for n in sys.argv[1:]:
print(n) #print out the filename we are currently processing
input = open(n, "r")
output = open(n + ".out", "w")
# do some processing
input.close()
output.close()
</code></pre>
<p>Then call it like:</p>
<pre>
./foo.py bar.txt baz.txt
</pre>
|
Forcibly rollback an installer in c# setup projects <p>I have created a custom action dll.I just want to check if a product with same name exists(Done).If yes tell the user to uninstall the product by throwing a InstallException.However if the products are installed in same directory the Install state of the prev product is removed & the install state of new product is copied in the base directory,due to which the prev product cannot be uninstalled.Is there any procedure to achieve a solution to this problem.</p>
|
<p>It sounds like you really want to use the Upgrade logic provided by the Windows Installer to find the other products and set a Property. The Property can then control a LaunchCondition (or a Type19 CustomAction). That way you don't need any CustomActions.</p>
|
How are most AS3 Video Players Created? <p>Are most flash video players created all programmatically? Or they done using static buttons that are referenced in classes? Is it better to create all your buttons on the fly or does it not really matter?</p>
|
<p>I've found the easiest way was to use AS3 video components and customize them as needed. For example, the play head does all the scrubbing for you automatically, but you can control placement and design.</p>
<p>Here's a great tutorial:
<a href="http://www.adobe.com/devnet/flash/articles/skinning_as3_flvcomp_03.html" rel="nofollow">http://www.adobe.com/devnet/flash/articles/skinning_as3_flvcomp_03.html</a></p>
|
How to summarize view-components/widgets-information in a JAR-File? <p>I would like to use an ajax toolkit/framework like ZK (www.zkoss.org) or GWT. But I don't know whether it's possible to bundle resources in a JAR? Do you know which one support such resource loading?</p>
|
<p>Not sure what your goal is, but if its to bundle a web application into one file, then you can do that with a WAR file - assuming your deploying onto a java webcontainer like tomcat or jboss.</p>
|
When should the Win32 InterlockedExchange function be used? <p>I came across the function <a href="http://msdn.microsoft.com/en-us/library/ms683590(VS.85).aspx">InterlockedExchange</a> and was wondering when I should use this function. In my opinion, setting a 32 Bit value on an x86 processor should always be atomic? <br/>
In the case where I want to use the function, the new value does not depend on the old value (it is not an increment operation).
Could you provide an example where this method is mandatory (I'm not looking for InterlockedCompareExchange)</p>
|
<p>As well as writing the new value, <code>InterlockedExchange</code> also reads and returns the previous value; this whole operation is atomic. This is useful for <a href="http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms">lock-free algorithms</a>.</p>
<p>(Incidentally, 32-bit writes are not guaranteed to be atomic. Consider the case where the write is unaligned and straddles a cache boundary, for instance.)</p>
|
Why does MSI require the original .msi file to proceed with an uninstall? <p>As most of you probably noticed, when uninstalling an MSI package Windows will ask for the original <code>.msi</code> file. Why is that?</p>
<p>I can only see disadvantages to that:</p>
<ul>
<li>not resilient to network changes.</li>
<li>not resilient to local disk changes.</li>
<li>unexpected by users.</li>
<li>typically requires users to leave their desk and start a crusade to get the correct CD.</li>
<li>kind of proves installations are not self-contained.</li>
<li>promotes the use of unsafe tools such as msizap.</li>
<li>which in turn promotes the "next time I'll just use a zip file" mentality.</li>
</ul>
<p>Could someone shed some light on this?</p>
|
<hr>
<p><strong>UPDATE</strong>:</p>
<p><del><a href="http://support2.microsoft.com/default.aspx?scid=kb;en-us;290301" rel="nofollow"><strong>This new support tool</strong></a></del> (this tool is now also deprecated) can be tried on recent Windows versions if you have <strong>defunct MSI packages needing uninstall</strong> (rather than the outdated, deprecated, unsupported <del>msizap.exe</del>).</p>
<hr>
<p><strong><em>Why are you asked for the original installation media?</em></strong>:</p>
<ul>
<li><strong>The original MSI is not needed for uninstall unless the MSI itself is badly designed - or the cached MSI is missing</strong> (see details below).</li>
<li>All installed MSI files are cached in <strong>%WINDIR%\Installer*.*</strong> using a <strong>random hex name</strong>.</li>
<li>The cached MSI file is used for any <strong>maintenance</strong> and <strong>uninstall</strong> operations - and it is sufficient for uninstall in the vast majority of cases.</li>
<li><em>In some cases <strong>this cached file can be missing</strong>, and then uninstall is not possible at all in some cases</em>. See more info below - and links to force uninstall or unregistration of the product.</li>
<li><strong>The original source</strong> is only needed if files need to be copied to disk (for a maintenance install), or the MSI does an <strong>explicit request</strong> to resolve the original source via the standard action <strong>ResolveSource</strong> or via a custom action (which <strong>shouldn't be done in a properly authored package</strong> - I think the MS Office package contained this ResolveSource error back in the day, causing everyone to go looking for their installation CDs/DVDs).</li>
<li>In previous editions of Windows this cached MSI was stripped of all cabs, and hence contained the installer structure only, and no files.</li>
<li>Starting with Windows 7 (<strong>MSI version 5</strong>) the <strong>MSI files are now cached full size</strong> to avoid breaking the file signature that prevents the UAC prompt on setup launch (a known Vista problem). This may cause a tremendous increase in disk space consumption (several gigabytes for some systems).</li>
<li>To prevent caching a huge MSI file, you can run an <strong>admin-install</strong> of the package before installing. This is how a company with proper deployment in a managed network would do things, and it will strip out the cab files and make a network install point with a small MSI file and files besides it. <em>Note that this may yield a <strong>UAC prompt</strong> is some cases since the extracted MSI file is no longer signed - this must be tested with your SOE / desktop configuration</em>.</li>
<li>Read my answer in this thread for the full description of admin installs: <a href="http://stackoverflow.com/questions/5564619/what-is-the-purpose-of-administrative-installation-initiated-using-msiexec-a">What is the purpose of administrative installation initiated using msiexec /a?</a> or this similar but perhaps more accessible answer: <a href="http://stackoverflow.com/questions/1547809/extract-msi-from-exe/24987512#24987512"><strong>admin install and its uses</strong></a></li>
<li><em>In some rare cases the cached MSI (with the random name) can be erroneously missing, and uninstall will then ask for the original MSI in order to complete the uninstall.</em> This does not happen often. It used to be the case that one could use <del><strong>MsiZap.exe</strong></del> to clean out such an install, but this tool is <strong>outdated</strong>, <strong>deprecated</strong> and <strong>unsupported</strong>. Don't use it - there are too many incompatibilities with newer Windows versions and you create new problems. Perhaps try <a href="http://support2.microsoft.com/default.aspx?scid=kb;en-us;290301" rel="nofollow"><strong>this support tool</strong></a> instead. If you want to figure out what could have caused the cached MSI to be missing, try to read section 12 here: <a href="http://stackoverflow.com/questions/450027/uninstalling-an-msi-file-from-the-command-line-without-using-msiexec/1055933#1055933">Uninstalling an MSI file from the command line without using msiexec</a> (in short potential causes range from interference with system restore, anti virus and cleanup scripts, to erronous manual tweaking, low disk space, power outages, developer box debugging errors, etc...)</li>
<li>As a <strong>last resort</strong> you can try <strong><a href="http://en.wikipedia.org/wiki/System_Restore" rel="nofollow">system restore</a></strong> (unless it has been disabled entirely or partly) to go back to a previous installation state and see if this solves your uninstall problem (you can find video demos of this on youtube or a similar site).</li>
<li>Be aware that system restore might affect Windows Update that must then be re-applied - as well as many other system settings. I have seen new, unsolvable installation problems resulting from a system restore, but normally it works OK. Obviously don't use the feature for fun, <strong>it's a last resort</strong> and is best used for <strong>rollback of new drivers</strong> or setups that have just been installed and are found to cause immediate problems and such issues. The longer you go back the more rework you will create for yourself.</li>
<li>Since I mentioned system restore I suppose I should mention <a href="http://support.microsoft.com/kb/307852" rel="nofollow">the Last Known Good Configuration feature</a>. This feature has nothing to do with uninstall or system restore, but is the last boot configuration that worked or resulted in a running system. It can be used to get your system running again if it bluescreens or halts during booting. This often happens after driver installs.</li>
</ul>
<p>Related answer: </p>
<ul>
<li><a href="http://stackoverflow.com/questions/334490/uninstall-without-msi-file/1061570#1061570">Uninstall Without MSI File</a></li>
</ul>
<hr>
<p>In addition to this answer, perhaps this article on various ways of uninstalling MSI packages is of interest. It is a <strong>rather popular article</strong> with a <strong>high number of views</strong>: </p>
<ul>
<li><strong><a href="http://stackoverflow.com/questions/450027/uninstalling-an-msi-file-from-the-command-line-without-using-msiexec/1055933#1055933">Uninstalling an MSI file from the command line without using msiexec</a></strong>. </li>
</ul>
|
How do I get the instance value of a property marked with a Attribute? <p>I have a class which is marked with a custom attribute, like this:</p>
<pre><code>public class OrderLine : Entity
{
...
[Parent]
public Order Order { get; set; }
public Address ShippingAddress{ get; set; }
...
}
</code></pre>
<p>I want to write a generic method, where I need to get the Property on a Entity which is marked with the Parent attribute.</p>
<p>Here is my Attribute:</p>
<pre><code>[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public class ParentAttribute : Attribute
{
}
</code></pre>
<p>How do I write this?</p>
|
<p>Use Type.GetProperties() and PropertyInfo.GetValue()</p>
<pre><code> T GetPropertyValue<T>(object o)
{
T value = default(T);
foreach (System.Reflection.PropertyInfo prop in o.GetType().GetProperties())
{
object[] attrs = prop.GetCustomAttributes(typeof(ParentAttribute), false);
if (attrs.Length > 0)
{
value = (T)prop.GetValue(o, null);
break;
}
}
return value;
}
</code></pre>
|
Naming of ID columns in database tables <p>I was wondering peoples opinions on the naming of ID columns in database tables.</p>
<p>If I have a table called Invoices with a primary key of an identity column I would call that column InvoiceID so that I would not conflict with other tables and it's obvious what it is.</p>
<p>Where I am workind current they have called all ID columns ID.</p>
<p>So they would do the following:</p>
<pre><code>Select
i.ID
, il.ID
From
Invoices i
Left Join InvoiceLines il
on i.ID = il.InvoiceID
</code></pre>
<p>Now, I see a few problems here:<br />
1. You would need to alias the columns on the select<br />
2. ID = InvoiceID does not fit in my brain<br />
3. If you did not alias the tables and referred to InvoiceID is it obvious what table it is on?</p>
<p>What are other peoples thoughts on the topic?</p>
|
<p>I always prefered ID to TableName + ID for the id column and then TableName + ID for a foreign key. That way all tables have a the same name for the id field and there isn't a redundant description. This seems simpler to me because all the tables have the same primary key field name. </p>
<p>As far as joining tables and not knowing which Id field belongs to which table, in my opinion the query should be written to handle this situation. Where I work, we always prefece the fields we use in a statement with the table/table alias. </p>
|
What is the reasoning for and the basic concepts behind an interstitial loading page? <p>I'm interested in finding out why this is used on some Web sites for processing user-initiated search submissions, how it affects the request and response flow, and programmatically why it would be necessary (or beneficial). In an MVC framework it seems difficult to execute since you are injecting another page into the middle of the flow.</p>
<p>EDIT:</p>
<p>Not advertising related. For instance, most travel sites used to do this, and there were no ads... some banking sites do it too, where there is just a loader that says something like "Please wait while we process your transaction...".</p>
|
<p>It is often used in long running requests to prevent the web server from timing out the request. With an interstitial page, you are able to continuously refresh the page until you get results back.</p>
<p>EDIT:</p>
<p>Also, for long running requests, it is beneficial to have a "Loading.." page in order to show the user that something is happening. Without the interstitial page, the request can appear to have hung up if it takes too long.</p>
|
Export all contacts as vcards from Outlook <p>So, I want to export all my contacts from Outlook as vcards. If I google that, I get a bunch of shareware programs, but I want something free that just works. </p>
<p>If I'm to code it myself, I guess I should use the Microsoft.Office.Interop.Outlook assembly. Has anyone already code to convert ContactItems to vcards?</p>
<p><strong>Edit:</strong> I solved it in a completely different way, see answer below, but I have marked dok1.myopenid.com's answer as accepted because it answers my original question. </p>
|
<p>I solved it in a non-programmatically way:</p>
<ul>
<li>Selected all contacts in Outlook</li>
<li>Forwarded them as cards to myself</li>
<li>Saved all the attachments (vcards) in a folder, <code>c:\temp</code></li>
<li>Opened a command prompt and typed the command <code>copy /a *.vcf c:\allcards.vcf</code> which concatenates all vcards into one</li>
</ul>
|
Aggregate Login Control [ASP.NET] <p>Is there a control out in the world that allows a user to log in to a website with MS Passport (Windows Live ID, whatever), Facebook, OpenID, etc. all in one control?</p>
<p>Thanks, everyone!</p>
|
<p>I am not aware of any control that allows all of them, but the API's are pretty simple that would allow you to implement it yourself.</p>
|
MFC: Showing / Hiding Splitter Panes <p>In my application I have a number of panes from m_wndspliter classes. What I want to do is at run time show and hide one of these panes. Whilst with the following code I can show and hide the view associated with the pane, I can't temporarily remove the pane itself. </p>
<pre><code>CWnd * pCurView = m_wndSplitter2.GetPane(2, 0);
if( !pCurView == NULL )
{
if( fShow )
{
pCurView->ShowWindow(SW_SHOW);
RecalcLayout();
}
else
{
pCurView->ShowWindow(SW_HIDE);
RecalcLayout();
}
}
</code></pre>
<p>Any examples / ideas ?</p>
<p>Thanks all.</p>
|
<p>You need to call CSplitterWnd::DeleteView to do this, which basically means that you have to save your CView elsewhere if you intend to restore it. Usually this is not a problem as all data should be stored in the CDocument rather than CView, but in practice this may not be the case.</p>
<p>The way I have handled this in the past is to have a copy constructor for my CView classes so I could easily store them in temporary variables.</p>
|
.net system tray application to launch when a USB device is plugged in <p>How do I get my .net system tray application to popup when a USB device is plugged in?</p>
|
<p>You might look <a href="http://www.codeproject.com/KB/system/DriveDetector.aspx" rel="nofollow">here</a> for an example app that does something like what you want.</p>
|
Nullable type as a generic parameter possible? <p>I want to do something like this :</p>
<pre><code>myYear = record.GetValueOrNull<int?>("myYear"),
</code></pre>
<p>Notice the nullable type as the generic parameter. </p>
<p>Since the <code>GetValueOrNull</code> function could return null my first attempt was this: </p>
<pre><code>public static T GetValueOrNull<T>(this DbDataRecord reader, string columnName)
where T : class
{
object columnValue = reader[columnName];
if (!(columnValue is DBNull))
{
return (T)columnValue;
}
return null;
}
</code></pre>
<p>But the error I'm getting now is:</p>
<blockquote>
<p>The type 'int?' must be a reference type in order to use it as parameter 'T' in the generic type or method</p>
</blockquote>
<p>Right! <code>Nullable<int></code> is a <code>struct</code>! So I tried changing the class constraint to a <code>struct</code> constraint (and as a side effect can't return <code>null</code> any more):</p>
<pre><code>public static T GetValueOrNull<T>(this DbDataRecord reader, string columnName)
where T : struct
</code></pre>
<p>Now the assignment:</p>
<pre><code>myYear = record.GetValueOrNull<int?>("myYear");
</code></pre>
<p>Gives the following error:</p>
<blockquote>
<p>The type 'int?' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method</p>
</blockquote>
<p>Is specifying a nullable type as a generic parameter at all possible?</p>
|
<p>Change the return type to Nullable, and call the method with the non nullable parameter</p>
<pre><code>static void Main(string[] args)
{
int? i = GetValueOrNull<int>(null, string.Empty);
}
public static Nullable<T> GetValueOrNull<T>(DbDataRecord reader, string columnName) where T : struct
{
object columnValue = reader[columnName];
if (!(columnValue is DBNull))
return (T)columnValue;
return null;
}
</code></pre>
|
How much does it cost to develop an iPhone application? <p>How much can a developer charge for an iPhone app like <a href="http://en.wikipedia.org/wiki/Twitterrific">Twitterrific</a>?</p>
<p>I want to know this because I need such an application with the same functionality for a new community website. I can do Ruby but have no experience with Objective-C. So it would be interesting for me if I should start reading books about iPhone programming or outsource the work to a iPhone programmer.</p>
|
<p>I'm one of the developers for Twitterrific and to be honest, I can't tell you how many hours have gone into the product. I can tell you everyone who upvoted the estimate of 160 hours for development and 40 hours for design is fricken' high. (I'd use another phrase, but this is my first post on Stack Overflow, so I'm being good.)</p>
<p>Twitterrific has had 4 major releases beginning with the iOS 1.0 (Jailbreak.) That's a lot of code, much of which is in the bit bucket (we refactor a lot with each major release.)</p>
<p>One thing that would be interesting to look at is the amount of time that we had to work on the iPad version. Apple set a product release date that gave us 60 days to do the development. (That was later extended by a week.)</p>
<p>We started the iPad development from scratch, but a lot of our underlying code (mostly models) was re-used. The development was done by two experienced iOS developers. One of them has even written a book: <a href="http://appdevmanual.com" rel="nofollow">http://appdevmanual.com</a> :-)</p>
<p>With such a short schedule, we worked some pretty long hours. Let's be conservative and say it's 10 hours per day for 6 days a week. That 60 hours for 9 weeks gives us 540 hours. With two developers, that's pretty close to 1,100 hours. Our rate for clients is $150 per hour giving $165,000 just for new code. Remember also that we were reusing a bunch existing code: I'm going to lowball the value of that code at $35,000 giving a total development cost of $200,000.</p>
<p>Anyone who's done serious iPhone development can tell you there's a lot of design work involved with any project. We had two designers working on that aspect of the product. They worked their asses off dealing with completely new interaction mechanics. Don't forget they didn't have any hardware to touch, either (LOTS of printouts!) Combined they spent at least 25 hours per week on the project. So 225 hours at $150/hr is about $34,000.</p>
<p>There are also other costs that many developer neglect to take into account: project management, testing, equipment. Again, if we lowball that figure at $16,000 we're at $250,000. This number falls in line with Jonathan Wight's (@schwa) $50-150K estimate with the 22 day Obama app.</p>
<p>Take another hit, dude.</p>
<p>Now if you want to build backend services for your app, that number's going to go up even more. Everyone seems surprised that Instagram chewed through $500K in venture funding to build a new frontend and backend. I'm not.</p>
|
Javascript registering event to object <p>I have an activex object I loaded into an html page. I then use that activex object to create another object, but I need to register an event with the new object created. The object is expecting an event listener of a certain type.</p>
<p>I can load this same dll in c# and it will work fine. Code looks like this for c#.</p>
<pre><code>upload = obj.constructUploadObj(uploadConfig);
upload.stateChanged += new UploadActionEvents_stateChangedEventHandler(upload_stateChanged);
</code></pre>
<p>In javascript I have similar code however I cannot get the event registered with the object.</p>
<pre><code>uploadAction = obj.constructUploadObj(uploadConfig);
uploadAction.stateChanged = upload_stateChanged;
function upload_stateChanged(sender){
writeLine("uploadState changed " + sender.getState());
}
</code></pre>
<p>I have enumerated some of the properties of the uploadAction object in javascript to ensure that it is actually created. When I try and register the event with uploadAction it throws an error saying "Object doesn't support this property or method."</p>
<p>To me it seems like its expecting a strongly typed event. Is there anyway to register the event similar to that of C# in javascript?</p>
<p>Thanks In Advance.</p>
|
<p>Your javascript should look something like this:</p>
<pre><code>function uploadAction::stateChanged( parms )
{
// ...
// implementation
// ...
}
</code></pre>
<p>Note, that this is a static function declaration, assuming that you have an Active X object named 'uploadAction'. I know that this does work - we use it at my company.</p>
|
Can I use Python as a Bash replacement? <p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p>
<p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to learning how to use Python to replace shell scripting, AWK, sed and friends?</p>
|
<p>Any shell has several sets of features.</p>
<ul>
<li><p>The Essential Linux/Unix commands. All of these are available through the <a href="https://docs.python.org/3/library/subprocess.html">subprocess</a> library. This isn't always the best first choice for doing <em>all</em> external commands. Look also at <a href="https://docs.python.org/3/library/shutil.html">shutil</a> for some commands that are separate Linux commands, but you could probably implement directly in your Python scripts. Another huge batch of Linux commands are in the <a href="https://docs.python.org/3/library/os.html">os</a> library; you can do these more simply in Python.</p>
<p>And -- bonus! -- more quickly. Each separate Linux command in the shell (with a few exceptions) forks a subprocess. By using Python <code>shutil</code> and <code>os</code> modules, you don't fork a subprocess.</p></li>
<li><p>The shell environment features. This includes stuff that sets a command's environment (current directory and environment variables and what-not). You can easily manage this from Python directly.</p></li>
<li><p>The shell programming features. This is all the process status code checking, the various logic commands (if, while, for, etc.) the test command and all of it's relatives. The function definition stuff. This is all much, much easier in Python. This is one of the huge victories in getting rid of bash and doing it in Python.</p></li>
<li><p>Interaction features. This includes command history and what-not. You don't need this for writing shell scripts. This is only for human interaction, and not for script-writing.</p></li>
<li><p>The shell file management features. This includes redirection and pipelines. This is trickier. Much of this can be done with subprocess. But some things that are easy in the shell are unpleasant in Python. Specifically stuff like <code>(a | b; c ) | something >result</code>. This runs two processes in parallel (with output of <code>a</code> as input to <code>b</code>), followed by a third process. The output from that sequence is run in parallel with <code>something</code> and the output is collected into a file named <code>result</code>. That's just complex to express in any other language.</p></li>
</ul>
<p>Specific programs (awk, sed, grep, etc.) can often be rewritten as Python modules. Don't go overboard. Replace what you need and evolve your "grep" module. Don't start out writing a Python module that replaces "grep".</p>
<p>The best thing is that you can do this in steps.</p>
<ol>
<li>Replace AWK and PERL with Python. Leave everything else alone.</li>
<li>Look at replacing GREP with Python. This can be a bit more complex, but your version of GREP can be tailored to your processing needs.</li>
<li>Look at replacing FIND with Python loops that use <code>os.walk</code>. This is a big win because you don't spawn as many processes.</li>
<li>Look at replacing common shell logic (loops, decisions, etc.) with Python scripts.</li>
</ol>
|
Powershell - Increase the timeout for retrieving XML from a URL <p>I'm trying to retrieve an XML stream from a URL. For most URLs my code below works fine. But, I have a couple URLs that timeout. The URLs in question <b>do</b> work from Internet Explorer.</p>
<pre><code>$webclient=New-Object "System.Net.WebClient"
[xml]$data=$webclient.DownloadString($url)
</code></pre>
<p>So, I went searching for a way to increase the timeout period. From what I've read, I believe I cannot do this using <code>System.Net.WebClient</code>. I think I need to use <code>System.Net.WebRequest</code> instead, but I cannot get it to work. The code I've been working on is below:</p>
<pre><code>$myHttpWebRequest = [system.net.WebRequest]::Create($url)
$myHttpWebRequest.Timeout = 600000
$myHttpWebResponse = $myHttpWebRequest.GetResponse()
$sr = New-Object System.IO.StreamReader($response.GetResponseStream())
[xml]$xml = [xml]$sr.ReadToEnd()
</code></pre>
<p>The URLs I'm trying to access are internal to my company, so I can't post them. But, they do work in IE and the actual URL should be irrelevant.</p>
<p>Ideas?</p>
<p>EDIT: Preliminary testing shows that adding <code>$myHttpWebRequest.AuthenticationLevel = "None"</code> works. Thanks Scott Saad.</p>
|
<p>By default the <strong>WebRequest.AuthenticationLevel</strong> is set to <strong>MutualAuthRequested</strong>, therefore it will wait for some type of authentication response. Therefore, a timeout is probably being exceeded while waiting for the authentication to occur. It didn't look like you were messing with the Credentials so unless you require authentication, you probably won't need this. Try something like the following after you create your <strong>WebRequest</strong>:</p>
<pre><code>$myHttpWebRequest.AuthenticationLevel = "None"
</code></pre>
<p>I hope this helps solve the problem.</p>
|
Payroll System Design, Business Logic in SPs or Application Layer (C#.Net), Maintainability - Repost <p>We are designing a Payroll Generation System for a client.</p>
<p>The organization we are targeting has a hierarchy as follows:
Company -> Cluster -> Business Unit (BU) -> Department -> Employee</p>
<p>The salary for an employee is made up of various salary components.
Each salary component has 3 rules associated with it, a Calculation Rule (Calculate component as % of another component, or % of a fixed number or a fixed number), an Eligibility Rule (whether an Employee/Dept is eligible for a component) and a Constraint Rule which limits tha max and min of a component.</p>
<p><strong>**These rules are editable and can be edited by a user end user</strong>. Also these rules are inherited top-down, but if defined at a lower level, the lower level rule takes precedence.**</p>
<p><strong>We have a database which has Attendance, Leaves, Bonuses tables and these rules are also supposed to interact with these tables.</strong></p>
<p>The client will be generating payroll for multiple clients each hosting a Separate Database instance. They may each have a different interpretation of each component and may have different components.</p>
<p>We are only looking to support SQL Server, and payroll generation will be an offline activity.</p>
<p><strong>We are divided upon where to put the logic which uses these rules to generate the individual tax components (which will include Tax Deductions, Tax Write-offs, Allowances, etc).</strong></p>
<p>Some people are advocating magic SPs which will take an employee Id and generate a payroll for that month.
Others want the logic to be split into separate components which will get the dependent data for an employee in the application layer and calculate these components there.</p>
<p>The order of our priorities are:
1. The ability to adapt changes to new clients quickly
2. Long term maintainability
3. Performance</p>
<p>1 and 2 outweigh 3 here by a large factor as this will be an offline activity.</p>
<p>Maintainability and Quick Customizability are very important, we will be deploying the application for different clients.
Client A may have a Salary Component Rule as ((0.3 * Basic) + 800)
and Client B as (0.2 * Basic) + (0.1 * Atendance Bonus)</p>
<p><strong>Will SPs cause a mess here, as the rules suggested above will be specified by the end user and will need to be customizable through a web UI.
We will have to parse the formulas from SQL. How difficult or easy will it be?
What advantage will doing this in the Application Layer (C# .Net) have over using SPs?</strong></p>
<p>The original post is here:
<a href="http://stackoverflow.com/questions/208707/design-hints-payroll-systemrepost">http://stackoverflow.com/questions/208707/design-hints-payroll-systemrepost</a>
...but none of the questions were properly answered.</p>
<p>Suggestions and pointers to existing systems' architecture will be very helpful.
...and yes, we are using LINQ to SQL elsewhere in the system.</p>
<p>Kind regards,
Ashish Sharma</p>
|
<p>I always try to shy away from putting business logic in the DB layer. It is more difficult to write, debug and maintain. In addition, the DB is generally the most expensive layer to scale. If you end up needing to beef up your system to support more users it is relatively cheap and easy to add new webservers to a system, but adding DB instances becomes expensive as each DB requires a license and additional support.</p>
|
Good freeware clone of the VMS editor EDT for unix or the pc? <p>I would like to have the same editor available on all of the platforms I frequent.</p>
<p>Emacs and Vi are not desired solutions.</p>
|
<p>There is <a href="http://www.asoft-dev.com/" rel="nofollow">nu/TPU</a> which is more like EVE/TPU, and also <a href="http://www.jedsoft.org/jed/" rel="nofollow">JED</a>, I've never found anything better than either of these. </p>
<p>I used to be the world's biggest fan of VMS and EVE/EDT/TPU - you're probably going to -1 me for saying this but why not <a href="http://www.bmen.tulane.edu/~rthart/EDTdescription.html" rel="nofollow">get edt mode for emacs</a>. There is a lot to be said for emacs in terms of speed and facilities and it is worth taking the time to learn enough to turn it into your editor of choice, which I think is why us folks who like emacs like it - because we can customise it to do what we want...</p>
<p>Currently I'm using Xemacs - customised to my keystrokes some of which came from EDT.</p>
|
Algorithm to order 'tag line' campaigns based on resulting sales <p>I want to be able to introduce new 'tag lines' into a database that are shown 'randomly' to users. (These tag lines are shown as an introduction as animated text.)</p>
<p>Based upon the number of sales that result from those taglines I'd like the good ones to trickle to the top, but still show the others less frequently.</p>
<p>I could come up with a basic algorithm quite easily but I want something thats a little more 'statistically accurate'.</p>
<p>I dont really know where to start. Its been a while since I've done anything more than basic statistics. My model would need to be sensitive to tolerances, but obviously it doesnt need to be worthy of a PHD.</p>
<p><strong>Edit:</strong> I am currently tracking a 'conversion rate' - i.e. hits per order. This value would probably be best calculated as a cumulative 'all time' convertsion rate to be fed into the algorithm.</p>
|
<p>Looking at your problem, I would modify the requirements a bit -</p>
<p>1) The most popular one should be shown most often.
2) Taglines should "age", so one that got a lot of votes (purchase) in the past, but none recently should be shown less often
3) Brand new taglines should be shown more often during their first days.</p>
<p>If you agree on those, then a algorithm could be something like:</p>
<pre><code>START:
x = random(1, 3);
if x = 3 goto NEW else goto NORMAL
NEW:
TagVec = Taglines.filterYounger(5 days); // I'm taking a LOT of liberties with the pseudo code,,,
x = random(1, TagVec.Length);
return tagVec[x-1]; // 0 indexed vectors even in made up language,
NORMAL:
// Similar to EBGREEN above
sum = 0;
ForEach(TagLine in TagLines) {
sum += TagLine.noOfPurhcases;
}
x = random(1, sum);
ForEach(TagLine in TagLines) {
x -= TagLine.noOfPurchase;
if ( x > 0) return TagLine; // Find the TagLine that represent our random number
}
</code></pre>
<p>Now, as a setup I would give every new tagline 10 purchases, to avoid getting really big slanting for one single purchase. </p>
<p>The aging process I would count a purchase older than a week as 0.8 purhcase per week of age. So 1 week old gives 0.8 points, 2 weeks give 0.8*0.8 = 0,64 and so forth...</p>
<p>You would have to play around with the Initial purhcases parameter (10 in my example) and the aging speed (1 week here) and the aging factor (0.8 here) to find something that suits you.</p>
|
Map two lists into a dictionary in Python <p>Imagine that you have:</p>
<pre><code>keys = ('name', 'age', 'food')
values = ('Monty', 42, 'spam')
</code></pre>
<p>What is the simplest way to produce the following dictionary ?</p>
<pre><code>dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'}
</code></pre>
<p>This code works, but I'm not really proud of it :</p>
<pre><code>dict = {}
junk = map(lambda k, v: dict.update({k: v}), keys, values)
</code></pre>
|
<p>Like this:</p>
<pre><code>>>> keys = ['a', 'b', 'c']
>>> values = [1, 2, 3]
>>> dictionary = dict(zip(keys, values))
>>> print dictionary
{'a': 1, 'b': 2, 'c': 3}
</code></pre>
<p>Voila :-) The pairwise dict constructor and zip function are awesomely useful: <a href="https://docs.python.org/2/library/functions.html#func-dict">https://docs.python.org/2/library/functions.html#func-dict</a></p>
|
Pulling data out of quotes? <p>I'm looking for a regex that can pull out quoted sections in a string, both single and double quotes.</p>
<p>IE:</p>
<pre><code>"This is 'an example', \"of an input string\""
</code></pre>
<p>Matches:</p>
<ul>
<li>an example</li>
<li>of an input string</li>
</ul>
<p>I wrote up this:</p>
<pre><code> [\"|'][A-Za-z0-9\\W]+[\"|']
</code></pre>
<p>It works but does anyone see any flaws with it?</p>
<p>EDIT: The main issue I see is that it can't handle nested quotes.</p>
|
<p>How does it handle single quotes inside of double quotes (or vice versa)?</p>
<pre><code>"This is 'an example', \"of 'quotes within quotes'\""
</code></pre>
<p>should match</p>
<ul>
<li>an example
<li>of 'quotes within quotes'
</ul>
<p>Use a backreference if you need to support this.</p>
<pre><code>(\"|')[A-Za-z0-9\\W]+?\1
</code></pre>
<p>EDIT: Fixed to use a reluctant quantifier.</p>
|
Giving a custom UserControl an ID in rendered HTML <p>When I use a ASP:Calendar control, and give it an ID:</p>
<p><code><asp:Calendar runat="server" ID="MyCal" /></code></p>
<p>It looks like this in the rendered html:</p>
<p><code><table id="NameMangled_MyCal"... /></code></p>
<p>And I can access the element by ID in javascript like this:</p>
<p><code>var cal= document.getElementById("<%= MyCal.ClientID%>")</code></p>
<p><strong>However,</strong> When I make a custom user control that has-a calendar:</p>
<pre><code><%@ Control Language="C#" AutoEventWireup="true" CodeFile="WeeklyEventsCalendar.ascx.cs"
Inherits="WeeklyEventsCalendar" %>
<div>
<asp:Calendar runat="server" ID="InnerCal" Width="100%" OnDayRender="RenderCell" OnVisibleMonthChanged="ChangeMonth" Height="480px" />
</div>
</code></pre>
<p>And then give it an ID when I add it to my page...</p>
<p><code> <mvs:WeeklyEventsCalendar ID="WeeklyCal" runat="server" /></code> </p>
<p>That ID doesn't show up anywhere in the rendered HTML. all I get is </p>
<p><code><div> stuff </div></code></p>
<p>When I want</p>
<p><code><div id="NameMangled_WeeklyCal"> stuff <div></code></p>
<p>What am I doing wrong?</p>
|
<p>UserControls only render their contents, nothing else. What you could do is </p>
<pre><code><%@ Control Language="C#" AutoEventWireup="true" CodeFile="WeeklyEventsCalendar.ascx.cs"
Inherits="WeeklyEventsCalendar" %>
<div id="<%= this.ControlID %>">
<asp:Calendar runat="server" ID="InnerCal" Width="100%" OnDayRender="RenderCell" OnVisibleMonthChanged="ChangeMonth" Height="480px" />
</div>
</code></pre>
|
How can I give each <li> its own bullet image? <p>I have tried</p>
<pre><code><ul id="contact_list">
<li id="phone">Local 604-555-5555</li>
<li id="i18l_phone">Toll-Free 1-800-555-5555</li>
</ul>
</code></pre>
<p>with</p>
<pre><code>#contact_list
{
list-style: disc none inside;
}
#contact_list #phone
{
list-style-image: url(images/small_wood_phone.png);
}
#contact_list #i18l_phone
{
list-style-image: url(images/i18l_wood_phone.png);
}
</code></pre>
<p>to no avail. Only a disc appears. If I want each individual list item to have it's own bullet, how can I accomplish this with css, <strong><em>without using background images</em></strong>.</p>
<p>Edit : I have discovered that, despite what firebug tells me, the list-style-image rule is being overridden somehow. If I inline the rule, like so:</p>
<pre><code> <li id="phone" style="list-style-image: url(images/small_wood_phone.png);">Local 604-555-5555</li>
</code></pre>
<p>then all is well. Since I have no other rules in the test case I'm running that contains ul or li in the selector, I'm not sure why inlining gives a different result.</p>
|
<p>Try this:</p>
<pre><code>#contact_list li
{
list-style: none;
}
#contact_list li#phone
{
list-style-image: url('images/small_wood_phone.png');
}
#contact_list li#i18l_phone
{
list-style-image: url('images/i18l_wood_phone.png');
}
</code></pre>
|
Suspending and notifying threads when there is work to do <p>I have multiple threads (C# application running on IIS) running that all need to communicate with the same MQ backend. To minimize network traffic, I need to only send a backend request when there is work to be done. There will be one thread to monitor if there is work to be done, and it needs to notify the other threads that they should also begin processing. The current solution involves the monitor thread setting a global variable and having the other threads loop and check that, ie in the monitor thread:</p>
<pre><code>CheckIfWorkAvailable() {
while(true) {
if (queue.Empty != true) {
workToBeDone = true;
}
}//end while loop
}
</code></pre>
<p>and then in the worker threads:</p>
<pre><code>DoWork() {
while(true) {
if (workToBeDone == true) {
//do work...
}
else {
Thread.Sleep(x seconds)
}
}//end while loop
}
</code></pre>
<p>Can the monitor thread notify the worker threads when there is work to do instead of having them just loop and sleep? The worker threads also set a counter indicating they are working and the decrement it when their work is done so the workToBeDone flag can be set to false.</p>
|
<p>Check out <a href="http://msdn.microsoft.com/en-us/library/system.threading.waithandle.aspx" rel="nofollow">WaitHandle</a> and its descending classes. <a href="http://msdn.microsoft.com/en-us/library/system.threading.eventwaithandle.aspx" rel="nofollow">EventWaitHandle</a> may suit your needs.</p>
|
Regex greedy issue <p>I'm sure this one is easy but I've tried a ton of variations and still cant match what I need. The thing is being too greedy and I cant get it to stop being greedy.</p>
<p>Given the text:</p>
<pre><code>test=this=that=more text follows
</code></pre>
<p>I want to just select:</p>
<pre><code>test=
</code></pre>
<p>I've tried the following regex</p>
<pre><code>(\S+)=(\S.*)
(\S+)?=
[^=]{1}
...
</code></pre>
<p>Thanks all.</p>
|
<p>here:</p>
<pre><code>// matches "test=, test"
(\S+?)=
or
// matches "test=, test" too
(\S[^=]+)=
</code></pre>
<p>you should consider using the second version over the first. given your string <code>"test=this=that=more text follows"</code>, version 1 will match <code>test=this=that=</code> then continue parsing to the end of the string. it will then backtrack, and find <code>test=this=</code>, continue to backtrack, and find <code>test=</code>, continue to backtrack, and settle on <code>test=</code> as it's final answer.</p>
<p>version 2 will match <code>test=</code> then stop. you can see the efficiency gains in larger searches like multi-line or whole document matches.</p>
|
Remove a symlink to a directory <p>I have a symlink to an important directory. I want to get rid of that symlink, while keeping the directory behind it. </p>
<p>I tried <code>rm</code> and get back <code>rm: cannot remove 'foo'</code>.<br>
I tried <code>rmdir</code> and got back <code>rmdir: failed to remove 'foo': Directory not empty</code><br>
I then progressed through <code>rm -f</code>, <code>rm -rf</code> and <code>sudo rm -rf</code></p>
<p>Then I went to find my back-ups.</p>
<p>Is there a way to get rid of the symlink with out throwing away the baby with the bathwater? </p>
|
<pre><code># this works
rm foo
# versus
rm foo/
</code></pre>
<p>Basically, you need to tell it to delete a file, not delete a directory. I believe the difference between <code>rm</code> and <code>rmdir</code> exists because of differences in the way the C library treats each.</p>
<p>At any rate, the first should work, while the second should complain about foo being a directory.</p>
<p>If it doesn't work as above, then check your permissions. You need write permission to the containing directory to remove files.</p>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.