instruction stringlengths 0 30k ⌀ |
|---|
The C# newbie has another simple question!
Does C# have built-in support for parsing strings of page numbers? By page numbers, I mean the format you might enter into a print dialog that's a mixture of comma and dash-delimited.
Something like this:
1,3,5-10,12
What would be really nice is a solution that gave me back some kind of list of all page numbers represented by the string. In the above example, getting a list back like this would be nice:
1,3,5,6,7,8,9,10,12
I just want to avoid rolling my own if there's an easy way to do it. |
The C# newbie has another simple question!
Does C# have built-in support for parsing strings of page numbers? By page numbers, I mean the format you might enter into a print dialog that's a mixture of comma and dash-delimited.
Something like this:
1,3,5-10,12
What would be really nice is a solution that gave me back some kind of list of all page numbers represented by the string. In the above example, getting a list back like this would be nice:
1,3,5,6,7,8,9,10,12
I just want to avoid rolling my own if there's an easy way to do it.
<br /><br />
**Edit**
Thanks everyone.
I liked the format of [Keith's answer](http://stackoverflow.com/questions/40161/does-c-have-built-in-support-for-parsing-page-number-strings#40180) the best but his code had one small mistake which is correct in [kronoz's code](http://stackoverflow.com/questions/40161/does-c-have-built-in-support-for-parsing-page-number-strings#40207).
That would be this:
Enumerable.Range(startPage, endPage - startPage + 1)
From [the msdn page](http://msdn.microsoft.com/en-us/library/system.linq.enumerable.range.aspx), Enumerable.Range takes the start of the range and the ***count*** (eg number of items in the range), ***not*** the actual ending value. |
Migrating from ASP Classic to .NET and pain mitigation |
|asp.net|asp|migration| |
|asp.net|migration|asp-classic| |
|asp.net|asp-classic|migration| |
We're in the process of redesigning the customer facing section of our site in .NET 3.5. It's been going well so far, we're using the same workflow and stored procedures for the most part, the biggest changes are the UI, the ORM (from dictionaries to LINQ), and obviously the language. Most of the pages to this point have been trivial, but now we're working on the heaviest workflow pages.
The main page of our offer acceptance section is 1500 lines, about 90% of that is ASP, with probably another 1000 lines in function calls to includes. I think the 1500 lines is a bit deceiving too since we're working with gems like this
function GetDealText(sUSCurASCII, sUSCurName, sTemplateOptionID, sSellerCompany, sOfferAmount, sSellerPremPercent, sTotalOfferToSeller, sSellerPremium, sMode, sSellerCurASCII, sSellerCurName, sTotalOfferToSeller_SellerCurr, sOfferAmount_SellerCurr, sSellerPremium_SellerCurr, sConditions, sListID, sDescription, sSKU, sInv_tag, sFasc_loc, sSerialNoandModel, sQTY, iLoopCount, iBidCount, sHTMLConditions, sBidStatus, sBidID, byRef bAlreadyAccepted, sFasc_Address1, sFasc_City, sFasc_State_id, sFasc_Country_id, sFasc_Company_name, sListingCustID, sAskPrice_SellerCurr, sMinPrice_SellerCurr, sListingCur, sOrigLocation)
The standard practice I've been using so far is to spend maybe an hour or so reading over the app both to familiarize myself with it, but also to strip out commented-out/deprecated code. Then to work in a depth-first fashion. I'll start at the top and copy a segment of code in the aspx.cs file and start rewriting, making obvious refactorings as I go especially to take advantage of our ORM. If I get to a function call that we don't have, I'll write out the definition.
After I have everything coded I'll do a few passes at refactoring/testing. I'm just wondering if anyone has any tips on how to make this process a little easier/more efficient. |
We're in the process of redesigning the customer facing section of our site in .NET 3.5. It's been going well so far, we're using the same workflow and stored procedures for the most part, the biggest changes are the UI, the ORM (from dictionaries to LINQ), and obviously the language. Most of the pages to this point have been trivial, but now we're working on the heaviest workflow pages.
The main page of our offer acceptance section is 1500 lines, about 90% of that is ASP, with probably another 1000 lines in function calls to includes. I think the 1500 lines is a bit deceiving too since we're working with gems like this
function GetDealText(sUSCurASCII, sUSCurName, sTemplateOptionID, sSellerCompany, sOfferAmount, sSellerPremPercent, sTotalOfferToSeller, sSellerPremium, sMode, sSellerCurASCII, sSellerCurName, sTotalOfferToSeller_SellerCurr, sOfferAmount_SellerCurr, sSellerPremium_SellerCurr, sConditions, sListID, sDescription, sSKU, sInv_tag, sFasc_loc, sSerialNoandModel, sQTY, iLoopCount, iBidCount, sHTMLConditions, sBidStatus, sBidID, byRef bAlreadyAccepted, sFasc_Address1, sFasc_City, sFasc_State_id, sFasc_Country_id, sFasc_Company_name, sListingCustID, sAskPrice_SellerCurr, sMinPrice_SellerCurr, sListingCur, sOrigLocation)
I'm wondering if anyone has any tips to make this re-write any easier. The standard practice I've been using so far is to spend maybe an hour or so reading over the app both to familiarize myself with it, but also to strip out commented-out/deprecated code. Then to work in a depth-first fashion. I'll start at the top and copy a segment of code in the aspx.cs file and start rewriting, making obvious refactorings as I go especially to take advantage of our ORM. If I get to a function call that we don't have, I'll write out the definition.
After I have everything coded I'll do a few passes at refactoring/testing. I'm just wondering if anyone has any tips on how to make this process a little easier/more efficient. |
Regarding Java 1.5 and autoboxing there is an important "quirk" that comes to play when comparing Integer objects.
In Java, Integer objects with the values -128 to 127 are immutable (that is, for one particular integer value, say 23, all Integer objects instantiated through your program with the value 23 points to the _exact_ same object).
Example, this returns true:
Integer i1 = new Integer(127);
Integer i2 = new Integer(127);
System.out.println(i1 == i2); // true
While this returns false:
Integer i1 = new Integer(128);
Integer i2 = new Integer(128);
System.out.println(i1 == i2); // false
The == compares by reference (does the variables point to the same object).
This result may or may not differ depending on what JVM you are using. The specification autoboxing for Java 1.5 requires that integers (-128 to 127) always box to the same wrapper object.
A solution? =) One should always use the Integer.equals() method when comparing Integer objects.
System.out.println(i1.equals(i2)); // true |
Regarding Java 1.5 and [autoboxing](http://en.wikipedia.org/wiki/Autoboxing#Autoboxing) there is an important "quirk" that comes to play when comparing Integer objects.
In Java, Integer objects with the values -128 to 127 are immutable (that is, for one particular integer value, say 23, all Integer objects instantiated through your program with the value 23 points to the _exact_ same object).
Example, this returns true:
Integer i1 = new Integer(127);
Integer i2 = new Integer(127);
System.out.println(i1 == i2); // true
While this returns false:
Integer i1 = new Integer(128);
Integer i2 = new Integer(128);
System.out.println(i1 == i2); // false
The == compares by reference (does the variables point to the same object).
This result may or may not differ depending on what JVM you are using. The specification autoboxing for Java 1.5 requires that integers (-128 to 127) always box to the same wrapper object.
A solution? =) One should always use the Integer.equals() method when comparing Integer objects.
System.out.println(i1.equals(i2)); // true
More info at [java.net](http://today.java.net/pub/a/today/2005/03/24/autoboxing.html) Example at [bexhuff.com](http://bexhuff.com/2006/11/java-1-5-autoboxing-wackyness) |
Paging SQL Server 2005 Results |
|sql|paging| |
How do I page results in SQL Server 2005?
I SQL Server 2000, there was no reliable way todo this but I'm now wondering if SQL Server 2005 has any built in method.
What I mean by paging is, for example, if I list users by their username, I want to be able to only return the first 10 records, then the next 10 records and so on.
Any help would be much appriciated. |
I got it with:
select
1 as tag,
null as parent,
AccountNumber as 'root!1!clientID!element'
from
Location.LocationMDAccount
where
locationid = 'long-guid-here'
for xml explicit
Thanks!
Edit: I think I like KG's way better, but Chris Leon answered what I really was trying to do. I'm going to do it KG's way. I totally forgot you could manipulate FOR XML AUTO in such a way. |
I got it with:
select
1 as tag,
null as parent,
AccountNumber as 'root!1!clientID!element'
from
Location.LocationMDAccount
where
locationid = 'long-guid-here'
for xml explicit
Thanks! |
> Will access to these tables through
> the GUID key be slow?
There are other problems with GUIDs, you see GUIDs are not sequential, so inserts will be scattered all over the place, this causes page splits and index fragmentation
In SQL Server 2005 MS introduced NEWSEQUENTIALID() to fix this, the only problem for you might be that you can only use NEWSEQUENTIALID as a default value in a table |
I agree on the 7 item limit Boojiboy mentions. Beyond that, it may be worth looking at anonymous (or specialized) types, IDictionary, or indirection via primary key to another data source.
|
I think the "pure OOP" answer is that if operations on the class are invalid when certain members aren't initialized, then these members must be set by the constructor. There's always the case where default values can be used, but I'll assume we're not considering that case. This is a good approach when the API is fixed, because changing the single allowable constructor after the API goes public will be a nightmare for you and all users of your code.
In C#, what I understand about the design guidelines is that this isn't necessarily the only way to handle the situation. Particularly with WPF objects, you'll find that .NET classes tend to favor parameterless constructors and will throw exceptions if the data has not been initialized to a desirable state before calling the method. This is probably mainly specific to component-based design though; I can't come up with a concrete example of a .NET class that behaves in this manner. In your case, it'd definitely cause an increased burden on testing to ensure that the class is never saved to the data store unless the properties have been validated. Honestly because of this I'd prefer the "constructor sets the required properties" approach if your API is either set in stone or not public.
The one thing I *am* certain of is that there are probably countless methodologies that can solve this problem, and each of them introduces its own set of problems. The best thing to do is learn as many patterns as possible and pick the best one for the job. (Isn't that such a cop-out of an answer?) |
I think your question is more about the design of your classes than about the number of arguments in the constructor. If I needed 20 pieces of data (arguments) to successfully initialize an object, I would probably consider breaking up the class. |
what partition type are you using? having millions of small files in one directory it might be a good idea to use JFS or ReiserFS which have better performance with many small sized files. |
Mutexes are useful in situations where you need to enforce exclusive access to a resource accross multiple processes, where a regular lock won't help since it only works accross threads. |
I'm not sure you need to get the pdb file into the GAC. (At least, the fix I'm about to describe works just fine for debugging SharePoint web parts in VS2005, which have a similar problem.)
There's a checkbox marked "Enable Just My Code (Managed Only)" in Tools-->Options-->Debugging; if you uncheck it, then Visual Studio will happily load your pdb's from the bin\Debug folder where it built them. Probably. Can't hurt to try, anyhow... |
Should be simple:
foreach( string s in "1,3,5-10,12".Split(',') )
{
//try and get the number
int num;
if( int.TryParse( s, out num ) )
yield return num;
//otherwise we might have a range
else
{
//split on the range delimiter
string[] subs = s.Split('-');
int start, end;
//now see if we can parse a start and end
if( subs.Length > 1 &&
int.TryParse(subs[0], out start) &&
int.TryParse(subs[1], out end) )
//create a range between the two values
foreach( int i in Enumerable.Range( start, end ) )
yield return i;
}
}
|
|c|linux|64-bit| |
Some code that rounds up the division to demonstrate (C-syntax):
#define SINT64 long long int
#define SINT32 long int
SINT64 divRound(SINT64 dividend, SINT64 divisor)
{
SINT32 quotient1 = dividend / divisor;
SINT32 modResult = dividend % divisor;
SINT32 multResult = modResult * 2;
SINT32 quotient2 = multResult / divisor;
SINT64 result = quotient1 + quotient2;
return ( result );
}
Now, if this were User-space we probably wouldn't even notice that our compiler is generating code for those operators (e.g. _divdi3()_ for division). Chances are we link with 'libgcc' without even knowing it. The problem is that Kernel-space is different (e.g. no libgcc). What to do?
Crawl Google for a while, notice that pretty much everyone addresses the unsigned variant:
#define UINT64 long long int
#define UINT32 long int
UINT64 divRound(UINT64 dividend, UINT64 divisor)
{
UINT32 quotient1 = dividend / divisor;
UINT32 modResult = dividend % divisor;
UINT32 multResult = modResult * 2;
UINT32 quotient2 = multResult / divisor;
UINT64 result = quotient1 + quotient2;
return ( result );
}
I know how to fix this one: Override _udivdi3()_ and _umoddi3()_ with _do_div()_ from _asm/div64.h_. Done right? Wrong. Signed is not the same as unsigned, sdivdi3()_ does not simply call _udivdi3()_ , they are separate functions for a reason.
Have you solved this problem? Do you know of a library that will help me do this? I'm really stuck so whatever you might see here that I just don't right now would be really helpful.
Thanks,
Chad
|
Spread vs MPI vs zeromq? |
|networking|api|distributed|cluster-analysis|messaging| |
In one of the answers to [Broadcast like UDP with the Reliability of TCP][1], a user mentions the [Spread][2] messaging API. I've also run across one called [ØMQ][3]. I also have some familiarity with [MPI][4].
So, my main question is: why would I choose one over the other? More specifically, why would I choose to use Spread or ØMQ when there are mature implementations of MPI to be had?
[1]: http://stackoverflow.com/questions/31572/broadcast-like-udp-with-the-reliability-of-tcp#31629
[2]: http://spread.org
[3]: http://zeromq.org
[4]: http://www-unix.mcs.anl.gov/mpi/ |
Is there anyway to run ruby on rails applications on a windows box? |
|windows|ruby|ruby-on-rails| |
I'm looking to run Redmine, a Ruby on Rails app, on a vps windows box. The only thing I can really think of is running a virtual linux machine and hosting it from there. If that is my only option, am I going to run into problems running a virtual machine inside of a virtual machine?
Also, this will be an internal app, so performance isn't my number once concern. |
You can install SQLite and a Rails server like Mongrel on a Windows machine. I used Aptana to run a development environment, but I'm sure that there are better alternatives that don't require the IDE to be open to run. But this proves it is possible. |
My 2c:
I'd recommend basing your system on Debian - the aptitude system has become the de facto way to quickly install and update programs on Linux. As for windowing managers, in my opinion Xfce hits the right balance between being lightweight and functional. Also, for security only install essential network services like SSH. |
My 2c:
I'd recommend basing your system on [Debian][1] - the [apt][2] system has become the de-facto way to quickly install and update programs on Linux. [Ubuntu][3] is Debian based with an emphasis on usability and compatibility. As for windowing managers, in my opinion [Xfce][4] hits the right balance between being lightweight and functional. The Ubuntu-based [Xubuntu][5] would probably be a good match.
Remember - for security only install essential network services like SSH.
[1]: http://www.debian.org/
[2]: http://wiki.debian.org/Apt
[3]: http://www.ubuntu.com/
[4]: http://www.xfce.org/
[5]: http://www.xubuntu.org/ |
My 2c:
I'd recommend basing your system on [Debian][1] - the [apt][2] system has become the de-facto way to quickly install and update programs on Linux. [Ubuntu][3] is Debian based with an emphasis on usability and compatibility. As for windowing managers, in my opinion [Xfce][4] hits the right balance between being lightweight and functional. The Ubuntu-based [Xubuntu][5] would probably be a good match.
Remember - for security only install essential network services like SSH.
If it were my decision, I would set up a [PXE boot server][6] to easily install Ubuntu Server Edition to any computer on the network. The reason why I would choose Ubuntu is because it's the one I've had the most experience with and the one I can easily find help for. If I needed a windowing manager for the particular installation, I would also install either Xfce or [Blackbox][7]. In fact, I have an old laptop in my basement that I've set up in exactly this way and it's worked out quite well for me.
[1]: http://www.debian.org/
[2]: http://wiki.debian.org/Apt
[3]: http://www.ubuntu.com/
[4]: http://www.xfce.org/
[5]: http://www.xubuntu.org/
[6]: http://en.wikipedia.org/wiki/Preboot_Execution_Environment
[7]: http://en.wikipedia.org/wiki/Blackbox |
Using const is a reasonable choice.
You may also wish to check out the boost C++ library for their shared pointer implementation. It provides the advantages of pointers i.e. you may have the requirement to return a shared pointer to "null" which a reference would not allow.
http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/smart_ptr.htm
In your case you would make the shared pointer's type const to prohibit writes. |
> In Subversion (and CVS), the repository is first and foremost. In git
> and mercurial there is not really the concept of a repository in the
> same way; here changes are the central theme.
+1
The hassle in CVS/SVN comes from the fact that these systems do **not**
remember the parenthood of changes. In Git and Mercurial,
not only can a commit have multiple children, it can also have multiple
parents!
That can easily observed using one of the graphical tools, `gitk` or `hg
view`. In the following example, branch #2 was forked from #1 at
commit A, and has since been merged once (at M, merged with commit B):
o---A---o---B---o---C (branch #1)
\ \
o---o---M---X---? (branch #2)
Note how A and B have two children, whereas M has two **parents**. These
relationships are *recorded* in the repository. Let's say the maintainer of
branch #2 now wants to merge the latest changes from branch #1, they can
issue a command such as:
$ git merge branch-1
and the tool will automatically know that the *base* is B--because it
was recorded in commit M, an ancestor of the tip of #2--and
that it has to merge whatever happened
between B and C. CVS does not record this information, nor did SVN prior to
version 1.5. In these systems, the graph
would look like:
o---A---o---B---o---C (branch #1)
\
o---o---M---X---? (branch #2)
where M is just a gigantic "squashed" commit of everything that happened between A and B,
applied on top of M. Note that after the deed is done, there is *no trace
left* (except potentially in human-readable comments) of where M did
originate from, nor of *how many* commits were collapsed together--making
history much more impenetrable.
Worse still, performing a second merge becomes a nightmare: one has to figure out
what the merge base was at the time of the first merge (and one *has* to *know*
that there has been a merge in the first place!), then
present that information to the tool so that it does not try to replay A..B on
top of M. All of this is difficult enough when working in close collaboration, but is
simply impossible in a distributed environment.
A (related) problem is that there is no way to answer the question: "does X
contain B?" where B is a
potentially important bug fix. So, why not just record that information in the commit, since
it is *known* at merge time!
P.-S. -- I have no experience with SVN 1.5+ merge recording abilities, but the workflow seems to be much more
contrived than in the distributed systems. If that is indeed the case, it's probably because--as mentioned
in the above comment--the focus is put on repository organization rather than on the changes themselves.
|
Should be simple:
foreach( string s in "1,3,5-10,12".Split(',') )
{
//try and get the number
int num;
if( int.TryParse( s, out num ) )
yield return num;
//otherwise we might have a range
else
{
//split on the range delimiter
string[] subs = s.Split('-');
int start, end;
//now see if we can parse a start and end
if( subs.Length > 1 &&
int.TryParse(subs[0], out start) &&
int.TryParse(subs[1], out end) &&
end > start )
//create a range between the two values
foreach( int i in Enumerable.Range( start, end - start + 1) )
yield return i;
}
}
**Edit:** thanks for the fix ;-) |
Blackberry publishes its SDK on its web site. Its apps run J2ME, so with some Java experience it shouldn't be too difficult to get started. They also give you an emulator. Disclaimer: I have no experience in writing Blackberry apps, but I looked into it once.
I would not recommend a PalmOS based handset. I have written code for PalmOS and it's about as painful as writing raw Win32 code in C. Since Palm has switched its high end handsets to Windows Mobile, PalmOS will just remain stagnant and only run on the slower, less capable hardware.
If I were to write a mobile app, I'd agree that Windows Mobile is worth checking out. |
If you aren't content with DataRow or SqlDataReader, you should look at an ORM system like Linq to Sql or nHibernate, instead of re-inventing the wheel yourself.
(By the way, this is called the "ActiveRecord" pattern) |
Create object from database row |
|.net| |
Let's say I'm building a data access layer for an application. Part of that is that I have a class definition for a particular object that is stored in the database. Of course, the data access itself returns the results in the form of a datareader, typed or untyped dataset, or similar, usually with the data needed to create one object per row in the result set.
How would go about creating your object instances in the data layer? Would have a constructor that accepts a datarow? How would you make that type-safe? Or would you have it list out one parameter for each field you want to instantiate, even if there could be many fields. Would you mark this constructor 'internal'? |
Let's say I'm building a data access layer for an application. Typically I have a class definition for a each kind of object that is stored in the database. Of course, the actual data access retrieves data in the form of a datareader, typed or untyped dataset, or similar, usually with the data needed to create one object per row in the results.
How would you go about creating your object instances in the data layer? Would have a constructor that accepts a datarow? If so, how would you make that type-safe? Or would you have your constructor list out one parameter for each field you want to instantiate, even if there could be many fields? Would you mark this constructor 'internal'? |
Force unmount of NFS-mounted directory |
SQL Server 2000 does not keep track of this information for you.
There may be creative / fuzzy ways to guess what this date was depending on your database model. But, if you are talking about 1 table with no relation to other data, then you are out of luck. |
How do you printf an unsigned long long int? |
|c|syntax| |
#include <stdio.h>
int main() {
unsigned long long int num = 285212672; //FYI: fits in 29 bits
int normalInt = 5;
printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);
return 0;
}
Output:
My number is 8 bytes wide and its value is 285212672l. A normal number is 0.
I assume this unexpected result is from printing the unsigned long long int. How do you printf an unsigned long long int? |
Use the ll (el-el) long-long modifier with the u (unsigned) conversion.
printf("%llu", 285212672); |
Non-standard things are always strange :)
for the long long portion
under GNU it's `L`, `ll` or `q`
and under windows I believe it's `ll` only |
[OmniAudit][1] is a commercial package which implments auditng across an entire database.
A free method would be to write a trigger for each table which addes entries to an audit table when fired.
[1]: http://www.krell-software.com/omniaudit/index.asp |
I believe you'd need to perform a separate query to accomplish that unfortionately.
I was able to accomplish this at my previous position using some help from this page:
[Paging in DotNet 2.0][1]
They also have it pulling a row count seperately.
[1]: https://web.archive.org/web/20210510021915/http://aspnet.4guysfromrolla.com/articles/031506-1.aspx |
Karl is absolutely correct, there is no need to set objects to null after use. If an object implements IDisposable, just make sure you call IDisposable.Dispose() when you're done with that object (wrapped in a try..finally, or, a using() block). But even if you don't remember to call Dispose, the finaliser method on the object should be calling Dispose() for you.
I thought this was a good treatment:
[http://msdn.microsoft.com/en-us/magazine/cc163392.aspx][1]
and this
[http://www.marcclifton.com/tabid/79/Default.aspx][2]
[1]: http://msdn.microsoft.com/en-us/magazine/cc163392.aspx
[2]: http://www.marcclifton.com/tabid/79/Default.aspx |
Karl is absolutely correct, there is no need to set objects to null after use. If an object implements IDisposable, just make sure you call IDisposable.Dispose() when you're done with that object (wrapped in a try..finally, or, a using() block). But even if you don't remember to call Dispose, the finaliser method on the object should be calling Dispose() for you.
I thought this was a good treatment:
[http://msdn.microsoft.com/en-us/magazine/cc163392.aspx][1]
and this
[http://www.marcclifton.com/tabid/79/Default.aspx][2]
There isn't any point in trying to second guess the GC and its management strategies because it's self tuning and opaque. There was a good discussion about the inner workings with Jeffrey Richter on Dot Net Rocks here: [http://www.dotnetrocks.com/default.aspx?showNum=361][3] and
Richters book [CLR via C#][4] chapter 20 has a great treatment:
[1]: http://msdn.microsoft.com/en-us/magazine/cc163392.aspx
[2]: http://www.marcclifton.com/tabid/79/Default.aspx
[3]: http://www.dotnetrocks.com/default.aspx?showNum=361
[4]: http://www.compman.co.uk/scripts/browse.asp?ref=747022 |
The problem with the applet approach mentioned is that unless you have the end user modify their java security properties your applet will not have permission to save to the hard drive.
It may be possible using [Java Web Start](http://java.sun.com/developer/technicalArticles/Programming/jnlp/) (aka JNLP). I think that if it is a signed app it can get the extra permission to write to the hard drive. This is not too different from the download an exe approach. The problem with this is that the user has to have the correct version of Java installed and has to have the Java Web Start capability setup correctly.
I would recommend the exe approach as it will be the easiest for the non-technical users to use. |
You could use the IISReset command line tool to stop/restart iis. So you could write a simple batch file to stop iis, copy your files, and then restart iis. I'm not sure how to integrate this with the VS publish feature however. |
Don't you need to recompute the size of the scrollBox after the layout? |
Haskell:
My favorite general, less academic tutorial:
1. <a href="http://en.wikibooks.org/wiki/Haskell">The Haskell wikibook</a> which contains all of the excellent Yet Another Haskell Tutorial. (This tutorial helps with specifics of setting up a Haskell distro and running example programs, for example.)
Functional Programming with Haskell:
1. Laziness and program correctness, thinking functionally: <a href="http://www.amazon.com/Introduction-Functional-Programming-using-Haskell/dp/0134843460">Bird's Introduction to Functional Programming Using Haskell</a>
2. Lambda calculus, combinators, more theoretical, but in a very down to earth manner: <a href="http://www.amazon.com/Introduction-Functional-Programming-Cambridge-Computer/dp/0521277248/ref=sr_1_12?ie=UTF8&s=books&qid=1220054578&sr=1-12">Davie's Introduction to Functional Programming Systems Using Haskell</a>
|
<b>Haskell</b>:
My favorite general, less academic online tutorials:
1. <a href="http://en.wikibooks.org/wiki/Haskell">The Haskell wikibook</a> which contains all of the excellent Yet Another Haskell Tutorial. (This tutorial helps with specifics of setting up a Haskell distro and running example programs, for example.)
2. <a href="http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/overview.html">Write yourself a Scheme in 48 hours</a>. Get your hands dirty learning Haskell with a real project.
Books on Functional Programming with Haskell:
1. Lambda calculus, combinators, more theoretical, but in a very down to earth manner: <a href="http://www.amazon.com/Introduction-Functional-Programming-Cambridge-Computer/dp/0521277248/ref=sr_1_12?ie=UTF8&s=books&qid=1220054578&sr=1-12">Davie's Introduction to Functional Programming Systems Using Haskell</a>
2. Laziness and program correctness, thinking functionally: <a href="http://www.amazon.com/Introduction-Functional-Programming-using-Haskell/dp/0134843460">Bird's Introduction to Functional Programming Using Haskell</a>
|
`readelf` will indeed help. You can use the `-S` option; that will show the sizes of all sections. `.text` is (the bulk of) your executable code. `.data` and `.rodata` is your static data. There are other sections too, some of which are used at runtime, others only at link time. |
@[Adam Davis][1]: Uhhh actually Adam, VSS is a horrible source control system. It has a long history of corrupting history and losing data. It is terrible at merging, doesn't handle multiple developers well and is very slow. Also the history is poor. Microsoft don't really support it any more, you'll note that they never used it for their own internal development and now they don't even sell it in favour of a more modern solution (VSTS). In short, if you have to choose between VSS and any other type of source control, go with the alternative.
[1]: http://stackoverflow.com/users/2915/adam-davis |
Just extending this out slightly from the original question, there are some of us doing Delphi Windows development work on virtual machines, too.
I've got a MacBook Pro (1st gen) with a couple of gigs of ram, and a recent iMac (with 4 gigs of ram). I've had more luck than xanadont with external drives, running a couple of different brands on Firewire 400 and finding them to be fine with 16-20Gb VMs. If I'm going to be in one place for a few days (either in the office on the iMac or on the road with the MBP) then I'll copy the VM to the local drive but as a rule it's worked fine for about 2 years now.
I started with Parallels, but there came a point when they started releasing versions that hadn't been regression tested, and sometimes basic stuff would suddenly be broken in the current release. Simple fix, stop downloading the new version and stay 3-6 months behind everyone else. Then I needed to give a VM to a colleague and had to go through a few hoops getting it out of Parallels and into VMware. At that point I tried the Fusion beta, had first-hand experience of moving a VM between Mac and Windows (with no real fuss at all) and that persuaded me to switch to Fusion. I have to say, Fusion is an excellent, stable, reliable tool.
I run WInXP Pro SP 3, Delphi 7, Delphi 2007, SQL Express and various development tools on my VMs (I tend to have a VM for each of my clients).
And I agree with xanadont about the 1Gig ram thing - mine tend to have a gig and no more - I didn't see any real change in behaviour/performance with >1Gb in the vm, so it's better off given to the host operating system rather than the virtual one. |
So after some research, here is what I found - a solution acceptable by the major search providers: [google][2] , [yahoo][1] & msn (I could on find a validator here) :
User-Agent: *
Disallow: /*
Allow: /?okparam=
Allow: /$
The trick is using the $ to mark the end of URL.
[1]: http://help.yahoo.com/l/us/yahoo/search/webcrawler/slurp-02.html
[2]: http://www.google.com/support/webmasters/bin/answer.py?answer=40367
|
I Am Not Getting the Result I Expect Using readLine() in Java |
|java|java-io| |
I am using the code snippet below, however it's not working quite as I understand it should.
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
try {
line = br.readLine();
while(line != null) {
System.out.println(line);
line = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
}
From reading the Javadoc about readLine() it says:
Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
**Returns**:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
**Throws**:
IOException - If an I/O error occurs
From my understanding of this, readLine should return null the first time no input is entered other than a line termination, like '\r'. However, this code just ends up looping infinitely. After debugging, I have found that instead of null being returned when just a termination character is entered, it actually returns an empty string (""). This doesn't make sense to me. What am I not understanding correctly? |
|linux|nfs|nfsclient| |
I have an NFS-mounted directory on a Linux machine that has hung. I've tried to force an unmount, but it doesn't seem to work:
$ umount -f /mnt/data
$ umount2: Device or resource busy
$ umount: /mnt/data: device is busy
If I type "`mount`", it appears that the directory is no longer mounted, but it hangs if I do "`ls /mnt/data`", and if I try to remove the mountpoint, I get:
$ rmdir /mnt/data
rmdir: /mnt/data: Device or resource busy
Is there anything I can do other than reboot the machine? |
You might try a lazy unmount. umount -l |
I highly encourage you to use an ORM tool. Even simple projects can make use of ORM quickly and quietly... in particular, look at [Castle][1]'s [ActiveRecord][2] tool (which sits on top of NHibernate to simplify model declaration).
[1]: http://www.castleproject.org/index.html
[2]: http://www.castleproject.org/activerecord/index.html |
How do I create a base page in WPF? |
|wpf| |
I have decided that all my WPF pages need to register a routed event. Rather than include
public static readonly RoutedEvent MyEvent= EventManager.RegisterRoutedEvent("MyEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(BasePage));
on every page, I decided to create a base page (named BasePage). I put the above line of code in my base page and then changed a few of my other pages to derive from BasePage. I can't get passed this error:
> Error 12 'CTS.iDocV7.BasePage' cannot
> be the root of a XAML file because it
> was defined using XAML. Line 1
> Position
> 22. C:\Work\iDoc7\CTS.iDocV7\UI\Quality\QualityControlQueuePage.xaml 1 22 CTS.iDocV7
Does anyone know how to best create a base page when I can put events, properties, methods, etc that I want to be able to use from any wpf page? |
|.net|wpf| |
How are you starting the command shell? With the TaskManager?
I suspect you might be starting it from Explorer - if I remember correctly, this could meen that you are inheriting the parent processes (Windows Explorer in this case) PATH variable. Since that was set before your installer ran, you see the old value.
Not sure if this helps... |
I think this depends on how you are starting the new Command shell. For example, when you change the PATH environment variable under System properties, the change isn't reflected until you open a new Command prompt. I think when you launch a new "cmd" process (from the Run dialog for example), you get a fresh copy of all environment variables, but if you launch the command prompt a different way then you do not.
For something done thru a script like that, you may need to restart before you notice the change. |
http://support.microsoft.com/kb/310519 says that for system environment variables (which PATH is one of) requires a restart, although I have a feeling that logging off and on may be enough. |
I'm not sure on this one, but looking at your error, I would try to define the base class with just c# (.cs) code - do not create one with XAML, just a standard .cs file that extends the WPF Page class. |
I use TortoiseSVN with VFP, and it mostly-seamlessly handles the case flipping. The only time it doesn't is if I have the file open in the IDE when I try to do the commit: the file lock VFP holds confuses it. Is this where your problem comes in, or are there other issues?
I did a presentation at FoxForward last year about using VFP with Subversion: most of the presentation dealt with the command line, but there are a couple of slides at the end that have links to tools that help you work with Subversion in VFP. http://docs.google.com/Presentation?id=dfxkh6x4_3ghnqc4 |
rix0rrr hit on it a bit, in that many tools are a pain to set up. Of course, I have my own solution to this problem that has been working quite well for the past few years. It's a project called [dbFacile][1]
I also wrote a bit of a [usage comparison][2] of the tools I found a few years ago. It's incomplete, but might give you a good starting point.
You mentioned that you don't want to embed raw queries but you don't want ORM, so I'm a bit confused about the middle ground you're hoping to find. I also have an [ORM project][3] that aims to require minimal setup and great ease of use.
The only requirement for my projects is PHP5.
[1]: http://greaterscope.net/projects/dbFacile
[2]: http://greaterscope.net/documentation/php_database_abstraction_class_comparison.html
[3]: http://greaterscope.net/projects/ORMer |
Something like this, perhaps:
<pre><code>
<?php
//Input file
$file = "myImage.png";
$img = ImageCreateFromPNG($file);
//Dimensions
$width = imagesx($img);
$height = imagesy($img);
$max_width = 300;
$max_height = 300;
$percentage = 1;
//Image scaling calculations
if ( $width > $max_width ) {
$percentage = ($height / ($width / $max_width)) > $max_height ?
$height / $max_height :
$width / $max_width;
}
elseif ( $height > $max_height) {
$percentage = ($width / ($height / $max_height)) > $max_width ?
$width / $max_width :
$height / $max_height;
}
$new_width = $width / $percentage;
$new_height = $height / $percentage;
//scaled image
$out = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($out, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//output image
imagepng($out);
?>
</code></pre>
I haven't tested the code so there might be some syntax errors, however it should give you a fair presentation on how it could be done. Also, I assumed a PNG file. You might want to have some kind of switch statement to determine the file type. |
You'll want to have "When the job completes" marked in your notifications page on the job's properties.
Just go to that dropdown and switch it to job completion instead of failure (which is on the screenshot).
![alt text][1]
[1]: http://uploader.ws/upload/200808/notifications.png
You'll also want to make sure that your server has e-mail configured. I think it's under SQL Surface Area Configuration for Features. |
How do people choose product names? |
|business|name| |
I flatter myself that I'm a good programmer, and can get away with graphic design. But something I'm incapable of doing is coming up with good names - and it seems neither are the people I work with. We're now in the slightly ludicrous situation that the product we've been working on for a couple of years is being installed to customers, is well received and is making money - but doesn't yet have a name.
We're too small a company to have anything like a proper marketing division to do this thing. So how have people tended to choose names, logos and branding? |
> What would you recommend?
XMPP through BOSH
There's no need to invent your own message format and transport protocol when somebody else has. If you try, it'll slowly grow to be just as complex as BOSH but without the benefit of third-party library support or standardization. |
$(this).corner();
See: http://www.methvin.com/jquery/jq-corner-demo.html |
You shouldn't ever really need to do this. Most software that **claims** to require the default instance (like Great Plains or Dynamics) doesn't actually.
If you repost with your situation (installed X, then Y, but need to accomplish Z) I bet you'll get some good workarounds. |
+1 for SQL Server Compact. It's free and there's no 'engine' in the sense of a full-time service, but you do have to deploy a runtime (it's just two .dll files). |
To the best of my knowledge, you can attach directly to the MDF (called a "user instance", rather than attaching the MDF to a "server instance") only if SQL Server Express is installed on that machine. So your machine that has MySql on it would also have to run SQL Server Express. |
Redmine ran fine on our Windows build server from the command line, sans IDE, using Mongrel and SQLite. Granted, ours isn't a VPS, but at any rate Linux isn't required for this app.
|
Ok, I worked around this. I made a custom ActionResult (HttpForbiddenResult) and custom ActionFilter (NoFallBackAuthorize).
To avoid redirection, HttpForbiddenResult marks responses with status code 403. FormsAuthentication doesn't catch responses with this code so the login redirection is effectively skipped. The NoFallBackAuthorize filter checks to see if the user is authorized much like the, included, Authorize filter. It differs in that it returns HttpForbiddenResult when access is denied.
The HttpForbiddenResult is pretty trivial:
<pre>
public class HttpForbiddenResult : ActionResult
{
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
context.HttpContext.Response.StatusCode = 0x193; // 403
}
}
</pre>
It doesn't appear to be possible to skip the login page redirection in the FormsAuthenticationModule. |
Experience with SVN vs. Team Foundation Server? |
|svn|subversion|tfs|teamfoundationserver|sourcecontrol| |
A few months back my team switched our source control over to [Subversion][1] from [Visual SourceSafe][2], and we haven't been happier. Recently I've been looking at [Team Foundation Server][3], and at least on the surface, it seems very impressive. There is some great integration with Visual Studio, and lots of great tools for DBA's, testers, project managers, etc.
The most obvious difference between these two products is price. It's hard to beat Subversion (free). Team Foundation Server is quite expensive, so the extra features would really have to kick Subversion in the pants.
My question is: does anyone have practical experience with both? How do they compare, and is Team Foundation Server actually worth all the money?
[1]: http://subversion.tigris.org/
[2]: http://msdn.microsoft.com/en-us/vs2005/aa718670.aspx
[3]: http://msdn.microsoft.com/en-us/tfs2008/default.aspx |
|python|podcast| |
How to send email from a program _without_ using a preexisting account? |
|.net|email|smtp| |
I'd like my program to be able to email me error reports. How can I do this without hard-coding a username/password/SMTP server/etc. into the code? (Doing so would allow users to decompile the program and take over this email account.)
I've been told you could do some stuff with telneting to port 25, but I'm very fuzzy on the details. Most of the code snippets on Google assume you have a preexisting account, which doesn't work in this situation.
I am using .NET v3.5 (C# in particular), but I would imagine the ideas are similar enough in most languages. As long as you realize I'm doing this for an offline app, and don't supply me with PHP code or something, we should be fine. |