To me that turn doesn't look like it lines up with the street I'm seeing over to the right of the picture - which makes me wonder if the turning lane is for something else and the no-right-turn sign is for that street to make sure people don't try to cut from that turning lane into it. I'm too lazy to try to track the street down in Google Maps to check though.
Posts made by fyjham
-
RE: To turn or not to turn, that is the question.
-
RE: Fight the Powah
In the interest of losing in performance to regex (example is in C#):
public static bool CheckPowerOfTwo(int value) { checked { try { for (int i=1; i < Int32.MaxValue; i++) { int powerOfTwo = 1; for (int j = 0; j < i; j++) { powerOfTwo = powerOfTwo * 2; if (powerOfTwo == value) return true; } } return false; } catch (OverflowException) { return false; } } }
Didn't let it play out long-term, but it took 20 seconds to do the first 4000, so in theory it should take a few months to do all integers...
-
RE: If an error message falls in a forest...
@JvdL said:
Logger.Warning("{0} is a moron because {1}", jvdl, designException);
The logger will handle such an invocation based on the severity (warning), the category derived by logger from CallingAssembly attributes and reflection. When sevcat merits logging, it compiles a message with time stamp, log text, user, source, machine, stack traces. It dispatches that to one or more handlers associated to that sevcat.
Sensible at this stage. Now let's pose the next question: What configures where the severity categories go? Does the framework itself dictate that these go to the console, or are you instead providing this from the calling Application when you initialize your logging framework (Either via configuration settings or programatically creating handlers for the levels)? If your framework takes it upon itself to decide to write it's errors to the stderr then you bet I'd disagree. If your framework is instructed by your calling code that errors at severity X go to stderr, so be it because then it's told you to do so.
You seem to have described your logging framework as dictating where thngs go, so in that regard I would say that either you shouldn't touch the UI from it or alternatively the application should (By configuration, parameters to a constructor, static methods, inherting a logger and implementing methods, or some variety of mystic voodoo chant) provide the logging framework with a mechanism for showing the error to the user. The fact the Logging layer may be deciding whether to show it is one thing, but the decision of whether "Show it on the UI" means it should be put into a HTML box with a red border, shown in a popup dialog above your forms application, written to standard error or printed out and strapped to the leg of a carrier pidgeon with instructions to deliver it to the user is a decision the UI layer should be making.
-
RE: If an error message falls in a forest...
@SEMI-HYBRID code said:
we may have different definitions of "doing stuff" then, because to me "displaying the data" falls into this cathegory just fine. besides, what is DirectX? Managed DirectX? OpenGL? And about every other presentation LIBRARY out there? worse than that, these DLLs interface directly with your hardware (as a fuckload of other does), making assumptions and/or requirements about its capabilities, which to me would be even worse than making a simple assumption that (software) console is present. if the reasoning behind why having DLL handle presentation layer (or using one) would be right, then innumerable libraries would become "incorrect", or unusable/futile, in a pursuit to make them "correct". including all the drivers that your computer uses.
Funnily enough, to have DirectX use the UI you have to give it a window handle (EG: Your display code has explicitly said "Please, draw all over this part of the UI"). OpenGL I don't have a great deal of experience with, but if I recall correctly once again you have to provide it with some kind of window or explicitly instruct it to create it's own. This falls under the "The UI has explicitly asked the DLL to do this, therefore go nuts" heading. As far as interfacing directly with the hardware... that's hardly the same as the UI. Unless you're referring to input hardware such as the keyboard etc, in which case most input libraries from these require the UI to explicitly tell them they want them to take over that input device. So those fit within the paradigm me and blakey were suggesting.
I don't think anyone's trying to say that DLL's should never touch the UI, moreso that they should not do so without the application explicitly requesting that they do and that wherever possible this interaction should be via an abstraction layer (Which in some cases like 3D graphics can not be an option due to performance).
@SEMI-HYBRID code said:
okay, then there's a question - does writing to console prevent the library from being a black box/working in a black box? how do you know the dll is not writing into console it has created for itself in the init function? what part of the snippet presented in the OP definitely says that it's using a console that it assumes is already there, created by someone else in advance?
Well, System.Console is a static class without a constructor in .NET, so I guess I'd have to say I don't know explicitly that this code hasn't already called SetOut on the standard console prior to doing this, but what I do know is that if the DLL in case of error without informing the application updates where the shared static class for writing to the console puts it's output then that would be even worse
-
RE: If an error message falls in a forest...
I'd have to agree with blakey here. I've always found it a little bit silly that Console is static in C#; would much prefer it to actually be an instance of an object so that if the UI doesn't want to give a handle to that object to another class (whether in a library or otherwise) then it can keep it's grubby hands off the interface.
While I wouldn't be so extreme as to say a DLL should never touch the UI or have UI logic in it, I would certainly agree that it shouldn't touch any part of the UI without the calling code explicitly handing it a reference to the UI it is going to work on. By all means a DLL can be passed Console.Out and Console.In and then do whatever it's meant to do with them, because at that point your UI-layer has essentially requested that the shared library perform actions on the UI itself. For a shared library to make an assumption, unsolicited by the calling code, that it can just go straight to the user interface without the UI layer being involved is just bad design. And if a bad design which is typically indicative of an error can be detected by the IDE/compiler then I agree a warning is a very good way to deal with it.
-
RE: Symantec is worse than many viruses
@Anonymouse said:
That's not entirely correct. Mostly because the definition of "good" can differ widely from application to application.
A hashing algorithm does not necessarily need to burn thousands of CPU cycles to be good (in fact, in a speed-critical application, that's the *last* thing you want).
A fast hashing algorithm is just not very desireable in a cryptographical context, but then, you can always stretch your keys...
Yeah, true, a hash can be used for many things, perhaps I should have said a good hashing algorithm for this task.
In context of what's being protected though you'd really need a slow hashing algorithm, or to use key stretching which has a net-result that your complete algorithm for generating your hash (Inclusive of stretching time) is a slow hashing algorithm despite using a slightly faster hashing algorithm at the core, to be secure enough for the task.
So yeah, you're right, but I think the core point still stands, just the statements don't necessarily apply in all contexts.
-
RE: Symantec is worse than many viruses
@sprained said:
Of course you could search. You hash the search input and then search for it against the stored hash.
That said, I'm not sure what the point would be of storing them other than for search purposes.
Only if you didn't salt the hashes, which would be fairly insecure and open to attack with rainbow tables pretty trivially.Otherwise you'd have to loop over every single record, get it's salt, hash your input against that salt and then compare it. Which assuming you have a lot of data (Symantec probably has a lot of customers in their system) and a hashing algorithm which is processor-intensive (Which it needs to be to be a good hashing algorithm) then that should take an incredibly long time to run that search.
-
RE: The Perfect Lack of Understanding
@snover said:
Writing $(document.getElementById('mcRdata_lg_'+a)) instead of $('#mcRdata_lg_'+a) makes sense—if you are getting paid per character. Otherwise it’s just fucking stupid.
I assume he was referring to the overload being available, as per dhromed's comment. I think (and hope) nobody's stupid enough to defend that approach.
-
RE: SavePageStateToPersistenceMedium In HTTPModule.
Hey,
Just grabbed that snippet for ya. This is something we use to compress the viewstate and we've been using it for a few years now across multiple sites with no real issues. Ours is overridden in a Page class that we use that all our pages inherit from not in a HttpModule though... The compression/decompression stuff references some of our internal libraries that I haven't included, shouldn't really need that part though if you're going for storing it server-side.
protected override object LoadPageStateFromPersistenceMedium()
{
string viewState = Request.Form["__VSTATE"];
byte[] bytes = Convert.FromBase64String(viewState);
bytes = Anonymized.CompressionTools.DeflateDecompress(bytes);
LosFormatter formatter = new LosFormatter();
return formatter.Deserialize(Convert.ToBase64String(bytes));
}
protected override void SavePageStateToPersistenceMedium(object viewState)
{
LosFormatter formatter = new LosFormatter();
System.IO.StringWriter writer = new System.IO.StringWriter();
formatter.Serialize(writer, viewState);
string viewStateString = writer.ToString();
byte[] bytes = Convert.FromBase64String(viewStateString);
bytes = Anonymized.CompressionTools.DeflateCompress(bytes);
ScriptManager.RegisterHiddenField(this, "__VSTATE", Convert.ToBase64String(bytes));
} -
RE: SavePageStateToPersistenceMedium In HTTPModule.
It's definitely quite possible to change what gets rendered into the viewstate, and so long as you override the methods that pull it back out you can do so seamlessly. I've used this previously to gzip the viewstate, but if you wanted to put an index in the viewstate and look it up from somewhere later there's no reason it wouldn't work. I'd question using the cache - given it could easily be cleared before the user returns, and I'd recommend at least some effort to avoid a user faking another's viewstate ID - but there's nothing fundamentally impossible about the concept.
Be sure to get the right save/load functions - there's more than one spot you can do it and some don't work with .NET AJAX. I don't recall exact methods but if you'd like I can track down that gzip code and post a snippet that'd help you on your way?
-
RE: .NET asmx error handling
Hey, I tried that exact method actually, but the problem is that'll only catch an error thrown by your handler code. If the inbound request is invalid (SoapAction not supported or the XML not matching the WSDL's schema) the error handling on that codeproject page .
I've basically wound up with a monstrosity that sniffs all the ASMX traffic and scans the XML for things that look like errors and forwards the raw XML in email if it finds one, which to me sounds more like a sidebar solution than a real error handling, so if anyone does know a good answer I'm still all ears even months after cause I haven't found a good answer :P
PS: There's this new invention called domain names... :P
-
RE: Which way?
@dhromed said:
@jchannell said:
but that's still a bit awkward, is it not?
Nope.Reads fine to me too... doesn't even seem remotely misleading. It actually took me a long time to even realize what you were talking about.
I like the don't drown sign though... It's like that old "Don't drink drive, you might hit a bump and spill your beer!" :)
-
RE: If the language developers cannot get it right...
@PSWorx said:
Huh... doesn't work on Firefox with fake IE user agent either. Any idea what IE does different?
<edit> Apparently it works on everything except Firefox. I'm baffled.
Clearly all hackers use Firefox, so there's no point wasting processor cycles escaping inputs from any other browser...
...
...
-
RE: .NET asmx error handling
Yeah, the HttpModule approach was what I was aiming at with the global asax, but I couldn't seem to get my hands on the response stream. I did think it was a bit odd for there to be no way to do that though, and I found the Filter response parameter which allows you to make all the response data go through any Stream object, so I'm thinking maybe the answer is to just create one of those that buffers up the data and in the endrequest try to write a few simple commands for sniffing out things that are indicative of errors in the data.
It does seem sort of messed up that you'd have to do that given how well most of .NET's error handling hooks in, and doesn't really seem like a viable long-term solution cause it means adding a second layer of parsers to everything (Was hoping for something I could viably run on a live environment without a big performance impact).
As far as WCF based services go, I've been thinking of looking at them for future services but there's a lot of existing clients integrated against the asmx services and a lot of services to convert so without a serious benefit I doubt it'll happen. But for future ones it might help so I'll read into what error handling those have, thanks for the tip.
-
.NET asmx error handling
Hey,
I've been looking for ages to try to find a way to catch and log invalid requests to an ASMX webservice. By invalid requests, I mostly mean invalid SOAPAction values or inbound XML that doesn't validate against the WSDL. I can easily trap exceptions thrown from my own code once the SOAP handlers pass the commands down to my code, but I'm having absolutely no luck catching anything that goes wrong before it hands over that control.
So far I've tried making a SoapExtension and using the ProcessMessage step and trying to catch the errors but it appears they're caught further up the tree, as all I get is an Initialize event then it falls over without ever reaching ProcessMessage. I've also tried a global.asax, and I at least got to log the entire request there, but the error event doesn't fire cause .NET figures the ASMX has already handled it by sending back a Soap Fault/Soap Exception. I've even tried reading the output stream in the finished request event and was figuring I'd parse the XML for soap errors then just log all the raw data, but I couldn't get it to read the outputstream (presumably cause it's already being sent).
There's a part of me saying "It's not your code that has the error, it's theirs!", but the problem is when people can't work out how to use an API they're generally also too stupid to provide good debug info for us to find out what they're doing wrong. I've had to set it up before to just email me all raw input data from the asax that matched a set of rules to try to track down issues, and that just strikes me as horrible. Next stop is using reflection to trawl over the .NET assemblies to try to find somewhere where I can tie in or override functionality to get my hands on the error.
Anyone already butted heads with this issue before? Is this just something you can't do in an ASMX or is there some silly little thing I'm missing?
-
RE: Most verbose HTTP 404 message I've ever seen.
@henke37 said:
It's not just a 404, but it is indeed a 404.
404 really only apply to HTTP requests, which the failing call is not. It is a call to a .NET function for formatting URL.
Even if it was over HTTP I'd think it's more of a 400 than a 404, the problem is that the URL is in fact not even a valid URL not just a file that doesn't even exist. In fact the function being called, unless I'm mistaken, doesn't even care whether the file exists. It just formats the path for special path values (Starting with a ~/ for webroot is the only one I know off top of head).
-
RE: Most verbose HTTP 404 message I've ever seen.
The only real WTF is that someone left that stuff showing on a live website rather than having a custom error handler (Although it looks like their error handler is what crashed given it's from 404_aspx.Page_Load, personally I've always made sure there's a static HTML fallback if everything else fails).
That's not actually just a 404 either, that's an exception from a function in .NET due to it not being a valid URL, not just there not being a file in it.
-
RE: Null access is always fun
@amischiefr said:
It's Java, you don't need brackets on an if statement with a single line of execution after it.
Yeah, I get that. I mean as in both methods were intended when it wasn't null. But since the first returns that wasn't feasible ;) Sorta like this:
if (criteria == null)
{
return criteria.getDataBeanContainer();
return executeSQL(criteria, con, criteria.getSelect());
}@amischiefr said:
There is nothing I can think of that you would "want" to do with null in executing a SQL statement.
Indeed, hence the consideration that executeSQL may be trwtf (Unless I'm mistaken and it's part of java, but I'm pretty sure in java you'd have to at least write down the object it's in to call it if it wasn't part of the current object). There's obviously nothing "correct" about the code, I was just trying to find the actual point of mistake (Normally you can bring it all back to 1 thing, it's a classy kind of WTF when you can't even see what the person was trying to do :P
-
RE: Building web sites
@tster said:
I'm going to skip JS and CSS at least for the initial version. Maybe I'll put in some JS later if I feel like I need it. Is CSS something that I can retrofit into an existing site, or does it pretty much have to be designed with it from the beginning?
Depending on how you build it, you could easily wind up having to rewrite the HTML to support CSS (Especially if you did an oldschool-style table layout). Plus coding in XHTML/CSS is much easier than oldschool HTML so I'd seriously recommend giving it a go right off the bat. Really as far as CSS goes to make 99% of sites you only need to know a small subset of CSS. So long as you understand float, padding, margin, background, some ofthe font stuff and the different behaviour of inline (eg: span) and block (eg: div) elements you can go a long way without anything else.
Just in case you don't have it btw, I highly recommend getting firebug addon for firefox, makes bug-fixing in HTML tons easier.
As far as the back-end language, it's largely personal opinion. I'd base the choice off what you know and what your hosting is (If it's a pure MS system with MSSQL database etc I'd definitely go the .NET approach, if you're looking more at a linux/apache style setup then there's a fair bit of overhead to getting mono etc working so I'd steer clear and lean more to the perl/php options).
-
RE: Null access is always fun
I'm struggling to work out what was intended... My first though was that there should've been brackets with the if, but the first line would be a return anyway...
My second thought was that executeSQL might be really messed up and do something with a null that we want, but firstly it'd be much tidier to just pass it a null if that's the case and secondly it'd crash on the getSelect...
What was was the actual desired functionality? Just to throw an exception if it's passed a null or? (Just to try to get a glimpse into the mind of the original coder :P)
-
RE: Don't bother writing code
@DaveK said:
@rohypnol said:
No, who does the documentation for the function say it does. What's on second.@Mole said:
Whats does the documentation for the function say it does?
Exactly!
So I pick up the code and throw it to naturally?
-
RE: Who is JP?
@Weng said:
Too much work. Just take the check out with Firebug.
Or even less effort just submit a malformed HTML tag. It only filters it if you close your tag but I'm willing to bet most modern browsers will be kind enough to go into quirks mode and render your HTML anyway (at least for simple tags like img :P). Or if you just want to be a bastard and don't care about exploting just submit <!-- and comment out the rest of the site :P It's amazing how many filters rely on better formed HTML than browsers need to render.
-
RE: Proof that Less is More
@Code Dependent said:
In the USA, "Overstocked" would be handled this way:
We're overstocked, and you're the beneficiary! This surplus must be expedited! We've got huge warehouses full of books to clear out to make way for next year's selections. Our loss is your gain!
"Quantities are limited" would be handled this way:
Call today! Quantities are limited, and this opportunity won't last long. Hurry, before supplies run out!
Oh, yeah... that works together. Yeah, buddy.Ok, let's say you're overstocked and you have x books in your "huge warehouse" (nb: I'm assuming the warehouse is finite). Your optimal stock level is y. You only intend to sell (x-y) books at a low price, because after that you'll no longer be overstocked. So there is a limited quantity. The limit may be large, but there is a limit. If their sale went insanely well and they cleared ALL their stock would you expect them to order in more and still sell at overstocked clearance sale prices? No, because the quantity on sale is limited.
In fact, if the company expects to clear out their surplus stock quickly due to their sale prices I'd think both sentences in your post make perfect sense side-by-side. In fact, I'm pretty sure I've seen advertisements that essentially read identically to those put together. I think you're missing the implied "Quantities [at sale prices] are limited". Personally I thought, like the advertiser clearly did, that it went without saying.
As for the more important intellectual debate going on, perhaps if one was to incorporate time travel into the boxcar that travels at the speed of light they could produce an infinite loop? Admittedly you may run out of hobo's... but if you brought a few back with you through time you could produce a self-sustaining hobo-explotation loop... you may need to incorporate space travel and life support into the boxcar to not run out of space though... You know that's a pretty damn fancy boxcar, I want one!
-
RE: Proof that Less is More
Seems pretty obvious to me... they're overstocked and selling something on sale, and quantities are limited because if their excess stock all gets bought then they're not going to order in more and still sell it at a discount. Not telling people there's limited stock would be sort of bait-and-switch'y (Not sure if it'd count legally, but at least ethically). I suspect most people today know what a stock clearance sale is, but the second you assume intelligence of the human race it always backfires :P
I don't know about elsewhere in the world but "While stocks last" is a very common thing to see on sale advertisements here in Australia. This is just a different wording of the same message.
-
RE: New Support Guy probably needs clean pants now...
@powerlord said:
I don't know about SQLServer's development stuff, but Oracle's development stuff (SQL*PLUS and SQLDeveloper) start with transactions turned on, so until you COMMIT; everything is temporary
MSSQL doesn't. Probably because it's locking is very heavy-handed and keeping an open transaction with a change in it will cause ungodly amounts of problems for anyone else considering going near the database :P
-
RE: Which sorting algorithm is this?
@tgape said:
Actually, if it's for a high school class, then that's possibly the best possible 'completely obvious and intuitive sort algorithm'. It's the first sort algorithm I was shown in high school, for what it's worth.
The next step would be to show how it has some obvious areas for improvement - most specifically, the alteration to make it a more standard version as noted above... Err, as I'm thinking about it, the next step had been for the teacher to give us an assignment: 'think about this over the weekend, and try to come up with an improved version.'
Really? First I saw was more of a standard bubble-sort then moved to insertion then selection.
We did get the "implement your own sorting algorithm" one though. There was some rather scary results. One guy actually wrote a random-sort. It randomly picked 2 elements in the array and swapped them if they were wrong, and if it managed to go 1000 iterations over that without swapping anything it assumed the array was sorted (In his defense the WTF was intentional and the assignment wasn't graded :P)
-
RE: A password problem
It's amazing how sometimes how little bits of information that seem so fundamental to someone working in IT are just "something the computer does" to other people. I mean there's so many things about a BIOS password prompt, especially back in those days, that would be noteworthy (not the least of which is having to wait for windows to start again). Though I'd always take an oblivious user over someone who knows just enough to be dangerous :P
-
RE: Which sorting algorithm is this?
Yeah, looks like conceptually speaking it's a selection sort, however it definitely isn't the standard one nor an efficient one.
If you read the inner loop you'll see that while it shuffles the remaining elements in some semi-random manner when it ends the element at "index" is set to the lowest number of all those from index to items.length. The shuffling of the items at the end of the loop is essentially irrelevant.
Most implementations wouldn't swap the values around until it had decided precisely which element is the smallest, but once you realize that what it's doing to the rest of the array is irrelevant it's definitely closer to a selection sort than bubble-sort (Though whether it qualifies as a selection sort depends on how literally you interpret definitions).
-
RE: Debugging multithreaded issue
Yeah, that's an atomic assignment, but you're still making the non-atomic choice (at least in your example) to add node to the list.
I mean, are 2 threads able to have hold of node at the same time before it gets added to the stack? And what stops them both adding it? I mean sure, the add would be threadsafe, but the second add would be setting it's next to head->next, which would be itself. Sorta need to be positive that head->next != node before you enter that loop, and need to be sure of it in an atomic way with the actions of the loop, which would be quite a challenge. Unless of course node isn't shared between multiple threads before it enters the stack?
-
RE: Debugging multithreaded issue
Yeah, more what I meant was if you can identify the point where your code definitively decides to add something to the end of the list (The point after which it won't check if it's already there again) and the point where it gets it's reference to the final node in the list (Which I presume are close together - otherwise you're in a world of pain). Once you narrow down where the thread must be when the other one changes the data you can simply freeze a single thread at that point and see whether the other threads wait for it or whether they update accordingly (Unless you think the check and the adding are an atomic step - which if you're not using mutexes I'm not sure how they would be).
-
RE: Debugging multithreaded issue
Simply leave the debug code in when you go live.
Just kidding, I'd normally just say lock the linked list, but it sounds like you're trying to achieve the opposite.
If adding debug code prevents debugging the only remaining course of action is simply to look at it logically. My guess would be that 2 threads try to add it to the end of the list at the same time, one gets added then the next one tries to put it on the end of the list which now consists of itself. Is the adding process thread-safe or? Other than that you could try putting assert (or your language's equivalent) statements in on the commands that change the linked list so you can find out which one is causing the issue, wouldn't have as much impact as debug output...
-
RE: Dynamic Order By for SQL query
@Salami said:
Why does all SQLhave to look pretty? Do what lpope suggested, but add another parameter for sort direction and an IF statement
Pretty I don't care about, maintainable I do. With duplicate code (Which let's face it, the second something is in 2 spots 1 gets updated and not the other at some point down the line), stored procedure needing to be updated for any new sortable column that comes along (Which is likely to occur) and the world's largest SQL case statement (For the number of columns that need to be sorted by) I just wouldn't think it was a highly maintainable enough solution.
I ended up going with an sp_executesql approach, just added some basic checking to prevent SQL injection (Sort direction must be asc or desc and column name passed in doesn't contain ] so I can safely just go [ColumnName] - if anyone is stupid enough to put a ] in a column name I'll rename their column instead of change the query - and also wrapped it at the DAL level in a check against the available columns before it gets passed to the stored procedure mostly just to get more sane errors if it's called wrong).I hated the idea of executing the SQL from a string, but since sp_executesql actually allows you to still make it a parameterized query I'm not as annoyed by it. It should still get compiled and executed with a shared execution plan (Well, one for each sort column/direction, but it's better than 1 for every SQL command).
Oh and vr602, the problem is that the app was already released once with the feature, and I was just doing the sorting in the display layer, and then the amount of data expected exponentially changed so they've come back for it to be optimized for the new amount of data. I've tried asking about removing the feature but it went nowhere, the "sweep it under the rug" tactic has been attempted and unfortunately I just don't have a big enough rug laying around :P
-
RE: Lots of snow
@DaveK said:
<g> It's a fairly old joke TBH... Other well-known units that also come in Imperial and Metric varieties are the boatload, crapton, fuckton, and shitload.[/quote][quote user="Renan "C#" Sousa"]
Maybe I is an acquaitance of snoofle.
Also, imperial fuckload FTW!
Gotta love the reactions you can get if you use it in a formal situation where the other person is expecting a real measurement. My favourite is the good ol' "approximately 1.2 metric shitloads" ;)
Or by the measurement system described [url]http://www.theregister.co.uk/2007/08/24/vulture_central_standards/[/url], 799442955.7 EU standard (Florentine) linguine (Unboiled at sea level), or 809357.6 brontosaurus's. And yes I'm incredibly depressed that I remembered that 2 and a half years later :P
-
RE: Centralized Application Configuration Management
Renan, while I agree with you in principal, I think you're exaggerating the downsides. Your point that the central config is going to have to be configured for each app is true and .NET's unfortunate unwillingness to do an include to a config file outside it's webroot is enough to bring tears to my eyes (Had a look for a simple solution once before but couldn't find any simple way to do it and came to that very conclusion - that any system to maintain it would be more overhead than it was worth when so many things already integrate so well with app/web.config files).
But on the caching point so long as you use decent threadsafe caching code you can reliably maintain a cache of an external config in the memory of a .NET app, reloading it if IIS decides to clear it out, with a bare minimum overhead. If you couldn't do that then the caching code would be entirely useless.
Your info on config caching is close to correct, .NET itself does cache the standard config files until they are edited or the app pool recycles, but it caches it basically in the same methods it exposes to you to allow you to cache other things (Including the ability to hook up a cache so that if a file is edited it is cleared - this is built-in to the available .NET cache code). If you had your own config file which you deserialized into an object then cached the object at a high priority with a dependency on the file then you'd essentially have rebuilt that functionality in code that could be easily done in 30 minutes (Obviously web.config will likely still have more capabilities than your custom config, but the parts to do with caching are easy to reproduce). For non-web apps they just read it when they first start then hold it in RAM the whole time, which is easy enough to achieve. The fact you'll still have to store where to find that config file and the fact you'll have to hook it into all your existing code is still a pretty big argument against doing this though.
Slavdude, I'm curious, is your goal to merge the configs so 1 change affects them all, or just to keep all the configs in 1 spot so they're easy to edit? Also are these applications serverside or are we talking apps with configs stored on end-user machines?
-
RE: I don't remember having that many network cards
Yeah, I've seen it happen for isolated icons before but never 19 icons at a time.
Do the third party drivers even control that icon? I was under the impression the generic windows network adapter code owned the icon and simply used the third party driver... I guess a defective driver'd still be in a pretty good position to break that code, but yeah I can't find anything conclusive to blame any specific adapter cause the icon wouldn't say what it was for before it vanished :p
-
I don't remember having that many network cards
Hey... last night on my laptop which has a grand total of 6 network adapters (1 wireless, 1 ethernet, 1 firewire, 2 VMWare, 1 Hamachi), 4 of which are set not to show their status in the status-bar, I saw a sight that was rather confusing that I thought I might share...
Despite the insistence that 19 of my 6 network adapters are unplugged I was still online... soon as I moused over any of them they got shy and disappeared, but poked their heads back up randomly until after my next reboot. Not sure whether to blame windows or the third-party virtual network cards that are installed, but either way I thought it was kinda classy :P
-
RE: List View Problems...
Yeah, Ragnax is right, the data item simply is not returned when the page is resubmitted. The following are ways you can get it back:
1) Data keys: If you specify DataKeyNames for your ListView and your DataSource is a typical one (Like a DataTable or an object with bindable parameters) then that field will be recorded for each row. Typically you'll set this to ID. Then there's an array of data keys in the control which you can look through to find the ID you need to go get your object.
2) CommandArgument: If your button is within the ListView row, you can set a CommandName and CommandArgument. The argument you'd typically databind to an ID or something so it's easy to look up when it posts back. Given your example shows a click event rather than an itemcommand event I suspect this doesn't apply.
3) HiddenField: Simply put an asp:HiddenField in your ListView and then loop through the rows in your listview and call FindControl on each to grab the hidden fields.
All of the above assume if you can get an ID of some sort you can recover your data object. Hope that helps ya.
-
RE: Update to null
It's so new they haven't given it a version number yet! :P
-
RE: IBM - Global Leader in Deforestation
Heh, we recently got a delivery of 5 hard drives from Dell. I forgot to take a picture, but here's a summary:
Each hard drive in the standard plastic protective box, which was then inserted into a plastic box that had slots for up to 12 or so hard drives (Though large enough that it could've easily had slots for 20+), which was then put in a cardboard box packed with packing foam, which was then put into a larger cardboard box then placed on a wooden pallette (Standard size - the size you'd normally have for a forklift), then shipped to our office and carried up the stairs by a delivery guy who was struggling to carry the whole thing (pallette and all).
The hilarious thing is that the packaging box was actually bigger than the box that the SAN the drives go into came in.
-
RE: Good coding style?
@yamikuronue said:
OK. See, that's what I thought, but the teacher keeps going on with hard and fast rules, so I wondered if it was just her personal preference she was teaching as rules or if there was some, I don't know, giant civil war resulting in some sort of treaty in which programmers swore to never again use do-while loops or something like that.
Nah, there's no real practical reason do-while loops are "poor form" per say. Like most coding tools there's good times to use them and bad times to use them like almost everything. It's coding patterns/structures that make bad code, not individual methods that should never be called. Only thing I've heard a general consensus as "poor form" are goto's, though even those have their places (Very limited places, but there is reasons for those to exist).
I'd probably say a do while loop is fine for what you're talking about, but as people have said you're generally best to follow instructions. Same can apply in the workforce, you'll come across coding conventions that won't match what you normally do, it's simply a fact, and for the sake of everyone else at the place you work you'll have to change your style to suit the conventions.
Most people I've heard object to do while have done so because they're used to the condition for a loop being at the top of the loop and find it less readable, but that's all personal preference and if the code inside the loop is split into functions correctly it shouldn't be that long of a loop body anyway ;)
As far as good things to do, it's hard to get a definitive list cause there's no magic bullet. Might be worth considering giving [url]http://en.wikipedia.org/wiki/Anti-pattern[/url] a skim though as a place to start, it's a list of bad coding styles (As opposed to specific methods) to avoid and why each is bad. End of the day if it's efficient, readable and maintainable it's good code ;)
-
RE: What do "Real World" Ant Scripts Look Like?
Only real Ant scripts I've run into with my work were to do with J2ME (micro edition, mobile phone basically) applications, and they were above-average complexity because we used the to create multiple builds of the application for different devices with different resources compiled in. They basically copy-pasted a pile of stuff to temp folders piecing together all the things needed for that device, ran some preprocessor directives and compiled it. There was some extra stuff like signing and FTP'ing the output but that was rarely used. As far as who wrote them I'm not entirely sure, they were there before I arrived and I never worked on enough stuff that used them to bother finding out. I do know they remain almost entirely unchanged since I showed up - they fill a specific role and they do it well so they're left alone (If they needed editing I'm pretty sure nobody would know how without doing some research - they were made to work then forgotten about).
We also use some nAnt scripts (basically .NET Ant scripts) which mostly deal with deploying sites to different servers with different web.config files for each environment with all the paths and access rights to deploy all stored in a cenral database and deploys controlled by webservices. I actually wrote most those myself to add some structure and try to replace the old deploy methodology (Copy/paste to live webserver via remote desktop straight from the developer's PC, I got scared every time a site got deployed though luckily very few actually went wrong =P).
-
RE: ExecuteScalar maybe?
Only real mistakes I can see right from that is not disposing the datatable and not using the built-in methods that exist explicitly for the purpose, but really in itself it's not too bad depending on the SQL that goes in. True it's re-inventing the wheel, but it's a very simple wheel and it spins just fine so who cares? ;)
GetData I could say a few more for, but we're looking for WTF's purely related to the GetOneItem method so that's all I got.
-
RE: Dynamic Order By for SQL query
What would be gained from doing it into the temp table rather than straight to the original table? Seems like overhead for no gain since it's still using a concatenated query going into a sp_executesql? Plus it loses the benefits of indexes that exist on the main table.
I guess it cuts the main query off from the sp_executesql but I can't see why that's a benefit over appending a sort to the main query then sp_executesql'ing it when sp_executesql allows everything else to stay parameterized. I wasn't aware it could do that till lpope's comment made me look at it - I've only really seen non-parameter dynamic SQL queries - which basically gets around my biggest problem with that approach so I'm thinking that's a solution.
I was thinking the same thing on the column names though, hadn't decided whether to find the available names or to just limit the names that can be put in to alphanumeric with no spaces (Hard to SQL inject with onlythat to work with. I prefer a white list to escaping wherever possible, much harder to miss something in a whitelist than blacklist ;)).
Thanks for the help, especially sp_executeSQL. With that to help I think I can safely avoid having to post my own solution on the sidebar :P
-
RE: Dynamic Order By for SQL query
@JesusChrist said:
Sadly this sounds all too familiar. Depending on what you're doing with the data is a sorting option at the UI level, ie, clickable column headers, viable or is this for a report or something?
That was my original approach, and is typically the way I do it just to save time despite it not being optimal for performance. But in this case the dataset is simply too large to actually load it all to the UI then sort it. The sheer amount of data transferred from the database server slows it to the point it takes like 5-10 seconds to sort the page which isn't really acceptable (Especially when the size of the database is likely to be at least 10 times larger by the end of the year ;))
-
RE: Dynamic Order By for SQL query
@vr602 said:
It may not be useful, but my first thought is, if you have to do something this awkward, is it really really needed? Perhaps there's a compromise that will keep the users perfectly happy and give you a lesser problem. For example, if you only had, say, 4 possible sort columns, the problem becomes trivial. Go and bully the BAs? Just saying...
Yeah, tried that first. No dice. I'm not convinced all the sorting options will ever be used after UAT, I reckon only 2 of the fields need a sort, but I am convinced short of a miracle the client won't budge on the requirement so it doesn't matter how useless it is ;)
-
RE: Everything I know is wrong!
@Mole said:
I remember having this before and the solution I found was to hex edit the files. The custom function changes to xxecute, and so execute is back to being a normal function again.
Simples! :-)
How elegant... and with no chance of unintended side-effects!
-
RE: Dynamic Order By for SQL query
Yeah, I considered that option, but I need to be able to change the asc/desc too. I guess that'd reduce it to 2 queries though, which is something, but it'd be a real mess with the number of fields it's on (Plus it'd be painful to add sorting by a new field which is basically guaranteed to come up a few times in the life of the app).
I didn't know about sp_executesql though, only execute, so that's a hell of a lot tidier. If I wrapped the sp_executesql call in a stored procedure of my own so that all it can change is the sort expression I think that could actually be a relatively neat way of dealing with this... Thanks =)
-
Dynamic Order By for SQL query
I've been pondering for a while now whether there's a way using MSSQL to dynamically determine what column should be ordered by in a select (EG: "SELECT * FROM table1 ORDER BY [b]column asc[/b]", dynamically editing the bold part). In a perfect world I'd love to make it parameter-driven but I'm pretty sure there's no simple way to achieve that...
I've google'd it a bit but it hasn't really been much help. The only ways I've come up with to achieve this are:
1. Defining all the possible queries in advance (Not so good because when you have a lot of columns you can sort on becomes painful to create and maintain)
2. Building the SQL query on the fly (Which I'd prefer not to do - while I could probably safely escape it I still think this is sort of poor form and typically all our queries are in XSD's and this would force it to be done differently to all other queries in the applications)
3. Building the query and using Exec in a stored procedure to run it (I'm leaning towards this, it removes a few of the disadvantages of option 2 like not using XSD's but I've got it in my head for obvious reasons to avoid Exec wherever possible).
4. Sorting it programatically (Which is nice and tidy, but unfortunately doesn't scale well when you start dealing with larger tables and are trying to return only a few hundred rows of data).Curious what people think is the "lesser evil", or if anyone has an option 5 I haven't considered yet...
-
RE: An interesting error...
Yeah, you're right, there is multiple possibilities that it could be. I was assuming the SocketException was coming from .NET's connection libraries and that .NET's code was blowing away the error value with it's cleanup code before throwing the exception - I guess that might not be the case though, cause the constructor for a SocketException isn't internal so anyone can produce one... I'd just really hope nobody would actually create one themselves because anything that might create one really should be going through the classes that'd create it for you if it's relevant anyway :P