instruction stringlengths 0 30k ⌀ |
|---|
you can try this trick that Scott Guthrie posted on his blog [http://weblogs.asp.net/scottgu/archive/2006/12/19/tip-trick-how-to-run-a-root-site-with-the-local-web-server-using-vs-2005-sp1.aspx][1]
to cut to the fix: select your project/solution in solution explorer and then open the Properties tab like you would if you were editing a textbox. If you right click and go to "Property Pages" that is the wrong place.
[1]: http://weblogs.asp.net/scottgu/archive/2006/12/19/tip-trick-how-to-run-a-root-site-with-the-local-web-server-using-vs-2005-sp1.aspx |
Your first step is to find and understand the parallelism in your problem. It is really easy to write multi-threaded code that performs no better than the single-threaded code it replaces. "Patterns for Parallel Programming" [(Amazon)][1] is a great introduction to the key concepts.
Once you have a workable design, start reading the articles in the "Concurrency" topic in the MSDN Magazine archives [(link)][2], particularly anything written by Jeff Richter. Those will give you the nuts and bolts stuff on the threading constructs specific to Windows and .NET. (The multi-threading section in Richter's "CLR via C# [(Amazon)][3]is short, but very insightful - highly recommended.)
[1]: http://www.amazon.com/Patterns-Parallel-Programming-Software/dp/0321228111/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1220134797&sr=8-1 "Amazon"
[2]: http://msdn.microsoft.com/en-us/magazine/cc159269.aspx
[3]: http://www.amazon.com/CLR-via-Second-Pro-Developer/dp/0735621632/ref=sr_1_1?ie=UTF8&s=books&qid=1220135008&sr=1-1 |
Take a look at how some of the popular PHP frameworks use templating. Examples include cakePHP, Zend Framework, and Code Igniter. Even if you are not going to base your site on these frameworks, the template design pattern is a good way to keep php code away from your web designers, so they can focus on layout and not functionality. |
I usually use includes, as they can be very useful for organising and grouping functions together. Also, comment your code. There's nothing worse than for someone else to see your work and not know why you've done this. Naming variables and functions sensibly can go a long way too - for example:
$userName = "John Doe";
$dateOfBirth = "04/02/1982";
function calculateUserAgeFromBirth($userName, $dateOfBirth)
Naming variables like this also helps minimise comments about *what* your code actually does.
|
Does the outside person need to edit the logic, or just the display (HTML)?
If it's the latter case, check out the [Smarty][1] template engine.
[1]: http://www.smarty.net/ |
@[Flávio Amieiro](#36420)
MeasureIt is an unnecessary extension to have if you install the Web Developer Toolbar. Web Developer Toolbar includes a ruler as one of its features. Under the "`Miscellaneous`" category for Web Developer click the option "`Display Ruler`" to use a ruler identical to the MeasureIt one.
That will allow you reduce the number of extensions needed by at least one. |
The ones I have are...
- [Y-SLow][1]
- [Live Headers][2]
- [Firebug][3]
- [Dom Inspector][4]
[1]: https://addons.mozilla.org/en-US/firefox/addon/5369
[2]: https://addons.mozilla.org/en-US/firefox/addon/3829
[3]: https://addons.mozilla.org/en-US/firefox/addon/1843
[4]: https://addons.mozilla.org/en-US/firefox/addon/6622 |
We considered it when we were looking at open source frameworks. But we saw the same thing your did that there really just isn't much support or information for it. You should always weight the community support factor surrounding open source projects before picking one. (which is what you are doing here) :) |
How to Test Numerical Analysis Routines? |
|testing|numerical| |
Are there any good online resources for how to create, maintain and think about writing test routines for numerical analysis code?
One of the limitations I can see for something like testing matrix multiplication is that the obvious tests (like having one matrix being the identity) may not fully test the functionality of the code.
Also, there is the fact that you are usually dealing with large data structures as well. Does anyone have some good ideas about ways to approach this, or have pointers to good places to look? |
Personally, the second one as everything you are using is in the direct order it will be output in. Whereas with the first you have to match up the {0} and {1} with the proper var, which is easy to mess up.
At least it's not as bad as the C++ sprintf where if you get the variable type wrong the whole thing will blow up.
Also, since the second is all inline and it doesn't have to do any searching and replacing for all the {0} things, the latter should be faster... though I don't know for sure. |
I think this depends heavily on how complex the output is. I tend to choose whichever scenario works best at the time.
Pick the right tool based on the job :D Whichever looks cleanest! |
For very simple manipulation I'd use concatenation, but once you get beyond 2 or 3 elements Format becomes more appropriate IMO.
Another reason to prefer String.Format is that .NET strings are immutable and doing it this way creates fewer temporary/intermediate copies. |
I prefer the second as well but I have no rational arguments at this time to support that position.
|
I've done a lot of work on this kind of parsing. Because there are errors you won't get 100% accuracy, but there are a few things you can do to get most of the way there, and then do a visual BS test. Here's the general way to go about it. It's not code, because it's pretty academic to write it, there's no weirdness, just lots of string handling.
(Now that you've posted some sample data, I've made some minor changes)
1. Work backward. Start from the zip code, which will be near the end, and in one of two known formats: XXXXX or XXXXX-XXXX. If this doesn't appear, you can assume you're in the city, state portion, below.
2. The next thing, before the zip, is going to be the state, and it'll be either in a two-letter format, or as words. You know what these will be, too -- there's only 50 of them. Also, you could soundex the words to help compensate for spelling errors.
3. before that is the city, and it's *probably* on the same line as the state. You could use a [zip-code database][1] to check the city and state based on the zip, or at least use it as a BS detector.
4. The street address will generally be one or two lines. The second line will generally be the suite number if there is one, but it could also be a PO box.
5. It's going to be near-impossible to detect a name on the first or second line, though if it's not prefixed with a number (or if it's prefixed with an "attn:" or "attention to:" it could give you a hint as to whether it's a name or an address line.
I hope this helps somewhat.
[1]: http://zipinfo.com |
|actionscript-3|naming|convention| |
I'm trying to write a RegEx for a code generator (in C#) to determine a proper class or package name of an AS3 class.
I know
- Must start with a letter (capital or otherwise)
- any other digit can be alphanumeric
- cannot have spaces
Is there anything else? |
If you're using C++ (or any other language with deterministic destructor execution when scopes end) you can take a look at [Scope Guards][1]. This technique can probably also be adapted to .NET by making ScopeGuard implement IDisposable and sprinkling "using" statements as needed.
[1]: http://www.ddj.com/cpp/184403758 |
[This article][1] seems like it would fit what you want. You'll need to change the saving imagejpeg() function to imagepng() and have it save the file to a string rather than output it to the page, but other than that it should be easy copy/paste into your existing code.
[1]: http://www.phpit.net/article/image-manipulation-php-gd-part2/ |
Authenticate on an ASP.Net Forms Authorization website from a console app |
|c#|asp.net|authentication| |
I'm trying to build a C# console application to automate grabbing certain files from our website, mostly to save myself clicks and - frankly - just to have done it. But I've hit a snag that for which I've been unable to find a working solution.
The website I'm trying to which I'm trying to connect uses ASP.Net forms authorization, and I cannot figure out how to authenticate myself with it. This application is a complete hack so I can hard code my username and password or any other needed auth info, and the solution itself doesn't need to be something that is viable enough to release to general users. In other words, if the only possible solution is a hack, I'm fine with that.
Basically, I'm trying to use HttpWebRequest to pull the site that has the list of files, iterating through that list and then downloading what I need. So the actual work on the site is fairly trivial once I can get the website to consider me authorized.
Thanks!
-Eric Sipple |
Is GD absolutely required? [ImageMagick][1] is faster, generates better images, is more configurable, and finally is (IMO) much easier to code for.
[1]: http://imagemagick.org/ |
I think [this page][1] is a good starting point. It uses imagecreatefrom(jpeg/gif/png) and resize and converts the image and then outputs to the browser. Instead of outputting the browser you could output to a BLOB in a DB without many minuttes of code-rewrite.
[1]: http://codecaine.co.za/posts/zend-image-class-to-convert-and-resize-images |
As for speeding up the IIS reset, Andrew Connell has some tips here as well
[http://www.andrewconnell.com/blog/archive/2006/08/21/3882.aspx
][1]
[1]: http://www.andrewconnell.com/blog/archive/2006/08/21/3882.aspx
This brought my IIS reset time from 10+ seconds down to less than 2 seconds.
|
|refactoring|url-rewriting| |
I'm sure you have all been there, you take on a project where there is a creaky old code base which is barely fit for purpose and you have to make the decision to either re-write it from scratch or repair what already exists.
Conventional wisdom tends to suggest that you should never attempt a re-write from scratch as the risk of failure is very high. So what did you do when faced with this problem, how did you make the decision and how did it turn out? |
I have a webpage about [rotary encoders and how to use them][1], which you might find useful.
Unfortunately without more information I can't troubleshoot your particular problem.
Which microcontroller pins are connected to the encoder, and what is the code you're currently using to decode the pulses?
-Adam Davis
[1]: http://www.ubasics.com/adam/electronics/doc/rotryenc.shtml |
I have a webpage about [rotary encoders and how to use them][1], which you might find useful.
Unfortunately without more information I can't troubleshoot your particular problem.
Which microcontroller pins are connected to the encoder, and what is the code you're currently using to decode the pulses?
Ok, you're dealing with a few different issues, the first issue is that this is a mechanical encoder, so you have to deal with switch noise (bounce, chatter). The [data sheet][2] indicates that it may take up to 3mS for the parts to stop bouncing and creating false outputs.
You need to create a debounce routine. The simplest of which is to continuously check to see if A goes high. If it does, start a timer and check it again in 3mS. If it's still high, then you can check B - if it's not high then you ignore the spurious pulse and continue looking for A high. When you check B, you look at it, start a timer for 3mS, and then look at B again. If it was the same both times, then you can use that value - if it changes within 3mS then you have to do it again (read B, wait 3mS, then read it again and see if it matches).
The atmega is fast enough that you shouldn't have to worry about these checks going slowly, unless you're also running a slow clock speed.
Once you deal with the mechanical noise, then you want to look at a proper gray code routine - the algorithm you're following won't work unless you also decrement if A is high when B goes low. Generally people store the last value of the two inputs, and then compare it to the new value of the two inputs and use a small function to increment or decrement based on that. (Check out the heading "high resolution reading" on the website I mentioned above for the table). I combine the two readings into a four bit number and use a simple array to tell me whether I increment or decrement the counter, but there are solutions that are even more advanced, and optimize for code size, speed, or ease of code maintenance.
-Adam Davis
[1]: http://www.ubasics.com/adam/electronics/doc/rotryenc.shtml
[2]: http://www.farnell.com/datasheets/103465.pdf |
You could simply put the elements in the set into a hash until you find a collision. In ruby, this is a one-liner.
def find_dupe(array)
h={}
array.detect { |e| h[e]||(h[e]=true; false) }
end
So, `find_dupe([1,2,3,4,5,1])` would return 1.
This is actually a common "trick" interview question though. It is normally about a list of consecutive integers with one duplicate. In this case the interviewer is often looking for you to use the Gaussian sum of *n*-integers trick e.g. `n*(n+1)/2` subtracted from the actual sum. The textbook answer is something like this.
def find_dupe_for_consecutive_integers(array)
n=array.size-1 # subtract one from array.size because of the dupe
array.sum - n*(n+1)/2
end
|
There's a nice [apache commons lang](http://commons.apache.org/lang/) library which has a good api for common :) actions. You could use statically import StringUtils and use its method isNotEmpty(String ) to get:
while(isNotEmpty(line)) {
System.out.println(line);
line = br.readLine();
}
It might be useful someday:) There are also other useful classes in this lib. |
For web developing I use the [Web Developer Toolbar](https://addons.mozilla.org/en-US/firefox/addon/60), [CSS Viewer](https://addons.mozilla.org/en-US/firefox/addon/2104) and [MeasureIt](https://addons.mozilla.org/en-US/firefox/addon/539).
But I'm really not one of those who has a thousand of extensions to do everything. I like to keep things simple. |
For web developing I use the [Web Developer Toolbar](https://addons.mozilla.org/en-US/firefox/addon/60), [CSS Viewer](https://addons.mozilla.org/en-US/firefox/addon/2104) <del>and [MeasureIt](https://addons.mozilla.org/en-US/firefox/addon/539).</del>
But I'm really not one of those who has a thousand of extensions to do everything. I like to keep things simple.
EDIT: Thanks to [Dan's answer](http://stackoverflow.com/questions/36407/firefox-add-ons#36433) I don't need MeasureIt anymore. Can't believe I've never seen that! I guess I'll just have to pay more atention to this WebDeveloper toolbar. |
There are many options and the best solution will depend on the nature of the problem you are trying to solve. If you are trying to solve an [embarassingly parallel][1] problem then dividing and parallelising the tasks will be trivial. In that case the challenge will come in distributing and managing the data used.
Some suggestions would be:
- [ICE Grid][2] which has bindings for .Net and other common languages
- [Velocity][3] which is Microsoft's version of Oracle (Tangersol) Coherence
- The forthcoming HPC offering from Microsoft [Compute Cluster Server][4]
- [Data Synapse Grid Server][5]
[1]: http://en.wikipedia.org/wiki/Embarrassingly_parallel
[2]: http://www.zeroc.com/icegrid/index.html
[3]: http://www.microsoft.com/downloads/details.aspx?FamilyId=B24C3708-EEFF-4055-A867-19B5851E7CD2&displaylang=en
[4]: http://www.microsoft.com/HPC/
[5]: http://www.datasynapse.com/ |
I took a "lisp class" in college back in the eighties. Despite grokking all the concepts presented in the class, I was left without _any_ appreciation for what makes lisp great. I'm afraid that a lot of people look at lisp as just another programming language, which is what that course in college did for me so many years ago. If you see someone complaining about lisp syntax (or lack thereof), there's a good chance that they're one of those people who has failed to grasp lisp's greatness. I was one of those people for a very long time.
It wasn't until two decades later, when I rekindled my interest in lisp, that I began to "get" what makes lisp interesting--for me anyway. If you manage to learn lisp without having your mind blown by closures and lisp macros, you've probably missed the point.
|
You don't need a "system" to do templating.
You can do it on your own by keeping presentation & logic separate.
This way the designer can screw up the display, but not the logic behind it.
Here's a simple example:
<?php
$people = array('derek','joel','jeff');
$people[0] = 'martin'; // all your logic goes here
include 'templates/people.php';
?>
Now here's the people.php file (which you give your designer):
<html>
<body>
<?php foreach($people as $name):?>
<b>Person:</b> <?=$name?> <br />
<?php endforeach;?>
</body>
</html>
|
Convert an ruby string with brackets to an array |
|ruby|arrays| |
I would like to convert the following string into an array/nested array:
str = "[[this, is],[a, nested],[array]]"
newarray = # this is what I need help with!
newarray.inspect # => [['this','is'],['a','nested'],['array']] |
How do I convert a Ruby string with brackets to an array? |
Althoug the documentation is poor on this topic, I managed to get some working code by looking at the source. Although it is missing the xml header which normally contains important information. Here is a small example program that does what you are looking for using rapidxml:
#include <iostream>
#include <sstream>
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_print.hpp"
int main(int argc, char* argv[]) {
char xml[] = "<?xml version=\"1.0\" encoding=\"latin-1\"?>"
"<book>"
"</book>";
//Parse the original document
rapidxml::xml_document<> doc;
doc.parse<0>(xml);
std::cout << "Name of my first node is: " << doc.first_node()->name() << "\n";
//Insert something
rapidxml::xml_node<> *node = doc.allocate_node(rapidxml::node_element, "author", "John Doe");
doc.first_node()->append_node(node);
std::stringstream ss;
ss <<*doc.first_node();
std::string result_xml = ss.str();
std::cout <<result_xml<<std::endl;
return 0;
}
|
[Here's a great thread][1] about serializing and deserializing objects in Silverlight 1.1.
As for a "best way," I'd say it would definitely be caching the xaml for the control and calling createFromXaml on it.
[1]: http://silverlight.net/forums/t/1730.aspx |
A more modern version of this is to use:
#pragma once
It is quite unusual to see this in a .c file, normally it is in the header files only. |
> So when you place the html link to the ugly domain name, assuming that it is the same PHP server (with the same sessions initialized), you can put it like this ...
> `www.myIsv.com/myWebSite/?PHPSESSID=<?=session_id()?>`
From a security point of view, I really really really hope that doesn't work |
Take a look at the oracle package DBMS_METADATA. In particular, the following methods are particularly useful: DBMS_METADATA.GET_DDL, DBMS_METADATA.SET_TRANSFORM_PARAM, DBMS_METADATA.GET_GRANTED_DDL. Once you are familiar with how they work (pretty self explanitory) you can write a simple script to dump the results of those methods into text files that can be put under source control. Good luck!
Not sure if there is something this simple for MSSQL. |
Security advice for jquery ajax data post? |
|security|jquery|ajax|post| |
I'm using jquery ajax to post updates back to my server. I'm concerned about making sure I have put in place appropriate measures so that only my AJAX calls can post data.
My stack is PHP on Apache against a MySQL backend.
Advice greatly appreciated! |
[A blog post covering several of the alternatives][1], including [PyGame][2], [PyCap][3], [SpriteCraft][4], and [ika][5]. I have also seen [pyglet][6] mentioned.
You may also want to look at [Panda][7], which is a very easy to use 3D engine with Python bindings. It is used for rapid prototyping at [Carnegie Mellon's ETC][8].
[1]: http://codeboje.de/2d-game-engines-python/
[2]: http://www.pygame.org/
[3]: http://www.farbs.org/pycap.html
[4]: http://www.suda-chen.biz/?page_id=9
[5]: http://ika.sourceforge.net/
[6]: http://www.pyglet.org/
[7]: http://panda3d.org/
[8]: http://www.etc.cmu.edu/ |
It's not so black and white... it really depends on a lot of factors (the more important being "what does the person paying you want you to do")
Where I work we re-wrote a development framework, and on the other hand, we keep modifying some old systems that cannot be migrated (because of the client's technology and time restrictions). In this case, we try to mantain the coding style and sometimes you have to implement a lot of workarounds because of the way it was built |
Refactor unless it is very bad indeed.
[Joel has a lot to say on this... ][1]
[1]: http://www.joelonsoftware.com/articles/fog0000000069.html
At the very least, rewrite the code with the old code in front of you and don't just start over from scratch. The old code may be terrible, but it is the way it is for a reason and if you ignore it you'll end up seeing the same bugs that were probably fixed years ago in the old code. |
Just clean up the code a little bit every time you work with it. If there isn't one already, setup a unit testing framework. All new code should get tests written. Any old code you fix as a result of bugs, try to slide in tests too.
As the cleanups progress, you'll be able to sweep more and more of the nasty code into encapsulated bins. Then you can pick those off one by one in the future.
A tool like javadoc or doxygen, if not already in use, can also help improve code documentation and comprehensibility.
The arguments against a complete rewrite a pretty strong. Those tons of "little bugs" and behaviors that were coded in over the time frame of the original project will sneak right back in again. |
Depends on how large/small/diverse the numbers are though. A radix sort might be applicable which would reduce the sorting time of the O(N log N) solution by a large degree. |
Just a small comment. Never ever go to the database direct. If there is no way to do it via published and supported API's, then there is no way to do it. End of story. This applies even to when you are "just reading data", as this can still cause significant issues. |
I don't understand... what do you mean by "having an MDF file in App_Data"? You need a proper SQL Server installation for that to work. You can always use the free SQL Server Express for developing the application, and then move the database to the proper SQL Server once you are done. Check [here][1].
[1]: http://www.microsoft.com/sql/editions/express/default.mspx |
Some folks in our company do that with their external dependencies, and they get occasional build errors, usually because a library or header can't be retrieved. When they rebuild again it all works. Of course the speed and traffic-level of your network would have a major effect on this. |
There are data services that given a zip code will give you list of street names in that zip code.
Use a regex to extract Zip or City State - find the correct one or if a error get both.
pull the list of streets from a [data source][1] Correct the city and state, and then street address. Once you get a valid Address line 1, city, state, and zip you can then make assumptions on address line 2..3
[1]: http://www.melissadata.com/lookups/zipstreet.asp |
Select Query on 2 tables, on different database servers |
|sql|asp|vbscript|sybase| |
I am trying to generate a report by querying 2 databases (Sybase) in classic ASP.
I have created 2 connection strings:<br>
> connA for databaseA<br>
connB for databaseB
Both databases are present on the same server (don't know if this matters)<br>
Queries:
> q1 = SELECT column1 INTO #temp FROM databaseA..table1 WHERE xyz="A"<br>
q2 = SELECT columnA,columnB,...,columnZ FROM table2 a #temp b WHERE b.column1=a.columnB
followed by:
> response.Write(rstsql) <br>
set rstSQL = CreateObject("ADODB.Recordset")<br>
rstSQL.Open q1, connA<br>
rstSQL.Open q2, connB
When I try to open up this page in a browser, I get error message:
>Microsoft OLE DB Provider for ODBC Drivers error '80040e37'
>[DataDirect][ODBC Sybase Wire Protocol driver][SQL Server]#temp not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output).
Could anyone please help me understand what the problem is and help me fix it?
Thanks. |
Have you compared with the [SHA1CryptoServiceProvider.ComputeHash][1] method? It takes a byte array and returns a SHA1 hash, and I believe it's pretty well optimized. I used it in an [Identicon Handler][2] that performed pretty well under load.
[1]: http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1cryptoserviceprovider.computehash.aspx
[2]: http://www.codeplex.com/Identicon/SourceControl/FileView.aspx?itemId=63541&changeSetId=3301 |
Generally I prefer the former, as especially when the strings get long it can be much easier to read.
The other benefit is I believe one of performance, as the latter actually performs 2 string creation statements before passing the final string to the Console.Write method. String.Format uses a StringBuilder under the covers I believe, so multiple concatenations are avoided.
It should be noted however that if the parameters you are passing in to String.Format (and other such methods like Console.Write) are value types then they will be boxed before passed in, which can provide its own performance hits. [Blog post on this here][1].
[1]: http://jeffbarnes.net/portal/blogs/jeff_barnes/archive/2006/08/08/Avoid-Boxing-When-Using-String.Format-with-Value-Types.aspx |
Maybe not an advanced technique, but one I see all the time that drives me crazy:
if (x == 1)
{
x = 2;
}
else
{
x = 3;
}
can be condensed to:
x = (x==1) ? 2 : 3; |
Calling .NET Web Service (WSE 2/3, WS-Security) from Java |
|.net|java|ws-security|wse|apache-axis| |
You didn't say what OS you're using but on Linux I been using a tabbed window manager ([wmii][1]) for a year or so and it has radically changed the way I use applications - consoles or otherwise.
I often have four or more consoles and other apps on a virtual desktop and with wmii I don't have to fiddle with resizing windows to line everything up just so. I can trivially rearrange them into vertical columns, stack them up vertically, have them share equal amounts of vertical or horizontal space, and move them between screens.
Say you open two consoles on your desktop. You'd get this (with apologies for the cronkey artwork):
----------------
| |
| 1 |
| |
----------------
----------------
| |
| 2 |
| |
----------------
Now I want them side-by-side. I enter SHIFT-ALT-L in window 2 to move it rightwards and create two columns:
------- -------
| || |
| || |
| 1 || 2 |
| || |
| || |
------- -------
Now I could open another console and get
------- -------
| || 2 |
| || |
| | -------
| 1 | -------
| || 3 |
| || |
------- -------
Then I want to temporarily view console 3 full-height, so I hit ALT-s in it and get:
------- -------
| | -------
| || |
| 1 || 3 |
| || |
| || |
------- -------
Consoles 2 and 3 are stacked up now.
I could also give windows tags. For example, in console 2 I could say ALT-SHIFT-twww+dev and that console would be visible in the 'www' and 'dev' virtual desktops. (The desktops are created if they don't already exist.) Even better, the console can be in a different visual configuration (e.g., stacked and full-screen) on each of those desktops.
Anyway, I can't do tabbed window managers justice here. I don't know if it's relevant to your environment but if you get the chance to try this way of working you probably won't look back.
[1]: http://www.suckless.org/wmii/
|
sudo gem install gemname
sudo gem update gemname |
Alignment restrictions for malloc()/free() |
|c|malloc| |
K&R (2nd ed.) and other C-language texts I have read that cover implementation of a dynamic memory allocator in the style of malloc() and free() usually also mention, in passing, something about alignment restrictions. Apparently certain platforms restrict how you can store and address certain values, requiring, for example, integers to be stored at addresses that are multiples of four. Do any major platforms (Intel & AMD, SPARC, Alpha) still impose these kinds of restrictions, or can I safely ignore it? |
> @John Topley: Thanks. Is there a
> similar command to update Ruby itself?
Not really. You don't say which operating system you're using. I use Mac OS X and tend to [build Ruby from source][1].
[1]: http://hivelogic.com/articles/2008/02/ruby-rails-leopard |
Alignment is still quite important today. Some processors (the 68k family jumps to mind) would throw an exception if you tried to access a word value on an odd boundary. Today, most processors will run two memory cycles to fetch an unaligned word, but this will definitely be slower than an aligned fetch. Some other processors won't even throw an exception, but will fetch an *incorrect* value from memory!
If for no other reason than performance, it is wise to try to follow your processor's alignment preferences. Usually, your compiler will take care of all the details, but if you're doing anything where you lay out the memory structure yourself, then it's worth considering. |
If you don't want to use an ORM you can also use reflection for things like this (though in this case because ProductID is not named the same on both sides, you couldn't do it in the simplistic fashion demonstrated here):
[List Provider in C#][1]
[1]: http://wiki.lessthandot.com/index.php/Generic_List_Provider_in_CSharp |
How to set up a DB2 linked server on a 64-bit SQL Server 2005 |
|sql-server|sqlserver2005| |
I need to create a linked server to a DB2 database on a mainframe. Has anyone done this successfully on a 64-bit version of SQL Server 2005? If so, which provider and settings were used.
It's important that the linked server work whether we are using a windows authenticated account to login to SQL Server or a SQL Server login. It's also important that both the 4-part name and OPENQUERY query methods are functional. We have one set up on a SQL Server 2000 machine that works well, but it uses a provider that's not available for 64-bit SS 2005. |
|sql-server| |
|sql-server|db2| |
[This page][1] should get you started. You need to first make a request to the page, and then saving the cookie to a container that you include in all later request. That should keep you logged in, and able to retrieve the files.
Hope this helps
[1]: http://www.netomatix.com/development/httpwebrequestredirect.aspx |
Here are a few links that might be helpful as an overview.
From my own experience, when I first started using MVC based web-frameworks the biggest issue I had was with the Models. Prying SQL out of my fingers and making me use Objects just felt strange. Once I started thinking of my data as Objects instead of SELECT statements it started getting easier.
- [MVC In laymen's terms][1]
- [MVC: The Most Vexing Conundrum][2]
- [How to use Model-View-Controller][3]
[1]: http://www.loudthinking.com/arc/000201.html "MVC: In laymen's terms"
[2]: http://www.slash7.com/articles/2005/02/22/mvc-the-most-vexing-conundrum
[3]: http://st-www.cs.uiuc.edu/users/smarch/st-docs/mvc.html |
If you want to use gdlib, use gdlib 2 or higher. It has a function called imagecopyresampled(), which will interpolate pixels while resizing and look much better.
Also, I've always heard noted around the net that storing images in the database is bad form:
- It's slower to access than the disk
- Your server will need to run a script to get to the image instead
of simply serving a file
- Your script now is responsible for a lot of stuff the web server used
to handle:
- Setting the proper Content-Type header
- Setting the proper caching/timeout/E-tag headers, so clients can properly cache the image. If do not do this properly, the image serving script will be hit on every request, increasing the load on the server even more.
The only advantage I can see is that you don't need to keep your database and image files synchronized. I would still recommend against it though. |
Can you compile Apache HTTP Server and redeploy its binaries to a different location ? |
|unix|apache|httpserver| |
As others have stated, the best performance comes from the bottom one since you are just rethrowing an existing object. The middle one is least correct because it looses the stack.
I personally use custom exceptions if I want to decouple certain dependencies in code. For example, I have a method that loads data from an XML file. This can go wrong in many different ways.
It could fail to read from the disk (FileIOException), the user could try to access it from somewhere where they are not allowed (SecurityException), the file could be corrupt (XmlParseException), data could be in the wrong format (DeserialisationException).
In this case, so its easier for the calling class to make sense of all this, all these exceptions rethrow a single custom exception (FileOperationException) so that means the caller does not need references to System.IO or System.Xml, but can still access what error occurred through an enum and any important information.
As stated, don't try to micro-optimize something like this, the act of throwing an exception at all is the slowest thing that occurs here. The best improvement to make is to try avoiding an exception at all.
<pre><code>
public bool Load(string filepath)
{
if (File.Exists(filepath)) //Avoid throwing by checking state
{
//Wrap anyways in case something changes between check and operation
try { .... }
catch (IOException ioFault) { .... }
catch (OtherException otherFault) { .... }
return true; //Inform caller of success
}
else { return false; } //Inform caller of failure due to state
}
</code></pre> |
Looking around, it seems some people resolved this by repairing or reinstalling the .NET SDK. You might want to give that a try.
P.S. I see why you didn't include more of the compiler output, now. Not much to really see there. :) |
This could also be accomplished by joining the table with itself,
SELECT DISTINCT t1.name
FROM tbl t1
INNER JOIN tbl t2
ON t1.name = t2.name
WHERE t1.key != t2.key; |
I don't know if this will help, but from [this forum][1]:
> Add an .ico file to the application section of the properties page, and recieved the error thats been described, when I checked the Icon file with an icon editor, it turn out that the file had more than one version of the image ie (16 x 16, 24 x 24, 32 x 32, 48 x 48 vista compressed), I removed the other formats that I didnt want resaved the file (just with 32x 32) and the application now compiles without error.
Try opening the icon in an icon editor and see if you see other formats like described (also, try removing the icon and seeing if the project will build again, just to verify the icon is causing it).
[1]: http://forums.msdn.microsoft.com/en-US/csharplanguage/thread/4217bec6-ea65-465f-8510-757558b36094/ |
I'd recommend picking up a copy of [Digital Video Compression][1] - it's a really good overview of compression algorithms for images and video.
[1]: http://isbn.nu/9780071424875/price |
Can you sniff the traffic to find what's actually being sent? Is it sending any auth data at all and it's incorrect or being presented in a form the server doesn't like, or is it never being sent by firefox at all? |
Ah, this is killing me! I did this at work about 3 months ago, and now I can't remember all the details.
I do remember, however, that you need basicHttpBinding, and you can't use the new serializer (which is the default); you have to use the "old" XmlSerializer.
Unfortunately, I don't work at the place where I did this anymore, so I can't go look at the code. I'll call my boss and see what I can dig up. |
I need to call a web service written in .NET from Java. The web service implements the WS-Security stack (either WSE 2 or WSE 3, it's not clear from the information I have).
The information that I received from the service provider included WSDL, a policyCache.config file, some sample C# code, and a sample application that can successfully call the service.
This isn't as useful as it sounds because it's not clear how I'm supposed to use this information to write a Java client. If the web service request isn't signed according to the policy then it is rejected by the service. I'm trying to use Apache Axis2 and I can't find any instructions on how I'm supposed to use the policyCahce.config file and the WSDL to generate a client.
There are several examples that I have found on the Web but in all cases the authors of the examples had control of both the service and the client and so were able to make tweaks on both sides in order to get it to work. I'm not in that position.
Has anyone done this successfully? |
For basic string concatenation, I generally use the second style - easier to read and simpler. However, if I am doing a more complicated string combination I usually opt for String.Format.
String.Format saves on lots of quotes and pluses...
Console.WriteLine("User {0} accessed {1} on {2}.", user.Name, fileName, timestamp);
vs
Console.WriteLine("User " + user.Name + " accessed " + fileName + " on " + timestamp + ".");
Only a few charicters saved, but I think, in this example, format makes it much cleaner.
|
Check out a book by [David Gries][1] called [The Science of Programming][2]. It's about proving the correctness of programs. If you want to be sure that your programs are correct (to the point of proving their correctness), this book is a good place to start.
Probably not exactly what you're looking for, but it's the computer science answer to a software engineering question.
[1]: http://en.wikipedia.org/wiki/David_Gries
[2]: http://www.amazon.com/Science-Programming-Monographs-Computer/dp/0387964800/ref=pd_bbs_2?ie=UTF8&s=books&qid=1219161068&sr=8-2 |
Based on the sample data:
1. I would start at the end of the string. Parse a Zip-code (either format). Read end to first space. If no Zip Code was found Error.
2. Trim the end then for spaces and special chars (commas)
3. Then move on to State, again use the Space as the delimiter. Maybe use a lookup list to validate 2 letter state codes, and full state names. If no valid state found, error.
4. Trim spaces and commas from the end again.
5. City gets tricky, I would actually use a comma here, at the risk of getting too much data in the city. Look for the comma, or beginning of the line.
6. If you still have chars left in the string, shove all of that into an address field.
This isn't perfect, but it should be a pretty good starting point.
|
Concatenating strings is fine in a simple scenario like that - it is more complicated with anything more complicated than that, even LastName, FirstName. With the format you can see, at a glance, what the final structure of the string will be when reading the code, with concatenation it becomes almost impossible to immediately discern the final result (except with a very simple example like this one).
What that means in the long run is that when you come back to make a change to your string format, you will either have the ability to pop in and make a few adjustments to the format string, or wrinkle your brow and start moving around all kinds of property accessors mixed with text, which is more likely to introduce problems.
If you're using .NET 3.5 you can use an extension method [like this one][1] and get an easy flowing, off the cuff syntax like this:
string str = "{0} {1} is my friend. {3}, {2} is my boss.".FormatWith(prop1,prop2,prop3,prop4);
Finally, as your application grows in complexity you may decide that to sanely maintain strings in your application you want to move them into a resource file to localize or simply into a static helper. This will be MUCH easier to achieve if you have consistently used formats, and your code can be quite simply refactored to use something like
string name = String.Format(ApplicationStrings.General.InformalUserNameFormat,this.FirstName,this.LastName);
[1]: http://james.newtonking.com/archive/2008/03/27/formatwith-string-format-extension-method.aspx |
As part of our product release we ship Apache HTTP Server binaries that we have compiled on our (UNIX) development machine.
We tell our clients to install the binaries (on their UNIX servers) under the same directory structure that we compiled it under. For some clients this is not appropriate, e.g. where there are restictions on where they can install software on their servers.
Is there a way of compiling Apache HTTP Server so its installation location(s) can be specified dynamically using environment variables ?
I spent a few days trying to sort this out and couldn't find a way to do it. It led me to believe that the Apache binaries were hard coding some directory paths at compilation preventing the portability we require.
Has anyone managed to do this ? |
|apache|unix|httpserver| |
As part of our product release we ship Apache HTTP Server binaries that we have compiled on our (UNIX) development machine.
We tell our clients to install the binaries (on their UNIX servers) under the same directory structure that we compiled it under. For some clients this is not appropriate, e.g. where there are restrictions on where they can install software on their servers and they don't want to compile Apache themselves.
Is there a way of compiling Apache HTTP Server so its installation location(s) can be specified dynamically using environment variables ?
I spent a few days trying to sort this out and couldn't find a way to do it. It led me to believe that the Apache binaries were hard coding some directory paths at compilation preventing the portability we require.
Has anyone managed to do this ? |
Take a look at the [Zend Framework][1], specifically Zend_Db. It has a Database Abstraction layer that doesn't require anything other than the MySQLi extension to be installed and isn't a full-blown ORM model.
[1]: http://framework.zend.com |