instruction stringlengths 0 30k ⌀ |
|---|
For Objective C:
Cocoa Programming for Mac OSX - Third Edition
Aaron Hillegass
Published by Addison Wesley
Programming in Objective C,
Stephen G Kochan, |
[Browsershots][1] is another option if you just want to get screenshots..
[1]: http://browsershots.org/ |
CSS not being applied on non authenticated ASP.NET page |
|asp.net|css| |
When developing (works fine live) the pages for our website don't pick up the correct CSS until the user has authenticated (logged on).
So the Logon and Logoff forms look bad, but once inside the site, the CSS works again.
I'm guessing it's some kind of authentication issue? Haven't really looked into it too much because it's only when working on dev so not a huge issue, but would be nice to know how to fix it. |
An empty web.config (or at least an absent *`<`system.web>* element) would mean that all of the framework's recommended defaults would take effect. You would then just need to be concerned with the host (e.g., IIS) set-up. |
For REALbasic:
Buginning REALbasic, From Novice to Professional by Jerry Lee Ford
*Very* basic, but a good way to get started |
Check and make sure that the CSS file itself is not in an area that you are securing. You can manually exclude the file via the web.config if needed. |
[Tip/Trick: Automating Dev, QA, Staging, and Production Web.Config Settings with VS 2005][1]
[1]: http://weblogs.asp.net/scottgu/archive/2007/09/21/tip-trick-automating-dev-qa-staging-and-production-web-config-settings-with-vs-2005.aspx |
If you don't have a copy of Windows that you could run in a virtual machine (VMware also isn't free), you can try [IEs4Linux][1]. It will require you configure some open source stuff on your Mac, but it is all free. You'll at least need fink, wine, and cabextract. See the link above for some specific command line directions. It's not that hard!
[1]: http://www.tatanka.com.br/ies4linux/page/Does_IEs_4_Linux_Work_with_Mac_OSX |
I have a project which has 120 or more exes, libs and dlls and takes a considerable time to build. I use a tree of batch files that call make files from one master batch file. I have had problems with odd things from incremental (or was it temperamental) headers in the past so I avoid them now. I do a full build infrequently, and usually leave it to the end of the day while I go for a walk for an hour (so I can only guess it takes about half an hour). So I understand why that is unworkable for working and testing.
For working and testing I have another set of batch files for each app (or module or library) which also have all the debugging settings in place -- but these still call the same make files. I may switch DEBUG on of off from time to time and also decide on builds or makes or if I want to also build libs that the module may depend on, and so on.
The batch file also copies the completed result into the (or several) test folders. Depending of the settings this completes in several seconds to a minute (as opposed to say half an hour).
I used a different IDE (Zeus) as I like to have control over things like .rc files, and actually prefer to compile from the command line, even though I am using MS compliers.
Happy to post an example of this batch file if anyone is interested. |
It looks like when the button is disabled .Net doesn't bother adding the necessary bits to handle the cross page postback on the client, so they will be missing when the button is enable client-side.
I guess one solution would be to have the button enabled to start with (so that .Net adds the cross page postback controls) and then disable it using javascript as soon as the control loads on the client. But this sounds a bit clunky. |
There is a <a href="https://secure-www.novell.com/center/regadmin/jsps/eval_app.jsp?buildid=GsODlkBPM2g~">60 day evaluation trial of Open Enterprise Server 2</a> available (requires free registration). If you install it in a VM, there's nothing stopping you from reinstalling it after 60 days (well except licence).
But you will need someone good with Linux to handle this (and preferably good with this precise technology). In a MS shop this might be a problem.
The easiest solution would be to outsource this - have some external techs test your software for compatibility. If you find out you are paying too much - hire someone who knows this software stack.
You can't support something if you don't test against it. And you can't test against something you don't know. |
There's the [pseudo-typedef antipattern][1]... Good stuff, drink up!
[1]: http://www.ibm.com/developerworks/library/j-jtp02216.html |
There's the [pseudo-typedef antipattern][1]...
class StringList extends ArrayList<String> { }
Good stuff, drink up! ;-)
As the article notes, this technique has some serious issues, primarily that this "typedef" is actually a separate class and thus cannot be used interchangeably with either the type it extends or other similarly defined types.
[1]: http://www.ibm.com/developerworks/library/j-jtp02216.html
|
Thanks for the link Keith, I'll have a look at that out of interest, as LINQ is on my list of things to learn. Unfortunately, I need to target .Net 2.0 for this app, so I think (please correct me if I'm wrong!) that LINQ is out of the question.
I've now included the CSS in the header of the XSLT, and I've found a way to use a System.Xml.Xsl.XslCompiledTransform object to transform the XML in memory. I'm currently using the WebBrowser.DocumentText property to pass the formatted XML into the WebBrowser componenet and this seems to work.
I can't help thinking that this isn't the best way of doing things, so any comments on better ways would be appreciated. In particular, if I were using LINQ, would I need a schema to bind to, and also, should I have a schema full-stop? I'm not great with XML, but I like Vaibhav's idea of generating straight from a schema rather than using a template. I'm just not sure where to start, so any pointers appreciated! |
If you want to unit test your WCF service classes make sure you design them with loose coupling in mind so you can mock out each dependancy as you only want to test the logic inside the service class itself.
On the client you can mock the WCF service itself using the interface of the service contract.
<TestMethod()> _
Public Sub ShouldPopulateProductsListOnViewLoadWhenPostBackIsFalse()
mMockery = New MockRepository()
mView = DirectCast(mMockery.Stub(Of IProductView)(), IProductView)
mProductService = DirectCast(mMockery.DynamicMock(Of IProductService)(), IProductService)
mPresenter = New ProductPresenter(mView, mProductService)
Dim ProductList As New List(Of Product)()
ProductList.Add(New Product)
Using mMockery.Record()
SetupResult.For(mView.PageIsPostBack).Return(False).Repeat.Once()
Expect.Call(mProductService.GetProducts()).Return(ProductList).Repeat.Once()
End Using
Using mMockery.Playback()
mPresenter.OnViewLoad()
End Using
'Verify that we hit the service dependency during the method when postback is false
Assert.AreEqual(1, mView.Products.Count)
mMockery.VerifyAll()
End Sub |
Umm no you don't; you can accept information cards on a web site using a cheap and cheerful certificate (but not self signed) or no certificate at all.
And yes, I've used it as part of a production system which grew out of a proof of concept I did at Microsoft.
Cons: If you don't have an EV SSL certificate you get warnings. The code for parsing a card is incomplete at best (you have to hack it around for no-SSL), you have to explain to users what one is.
Pros: Well that's more interesting; I was using managed cards and issuing them and then having 3rd parties use those to check claims; but for self issued cards; well, it's stronger than username password and doesn't have the same vulnerabilities OpenID has. |
@[brendan](#22875):
The article you cited is seriously outdated and the information is just plain wrong. Especially the last point (use `for` instead of `foreach`) is misleading and the justification offered in the article no longer applies to modern versions of .NET.
While it's true that the `IEnumerator` uses virtual calls, these *can* actually be inlined by a modern compiler. Furthermore, .NET now knows generics and strongly typed enumerators.
There are a lot of performance tests out there that prove conclusively that `for` is generally no faster than `foreach`. [Here's an example](http://diditwith.net/2006/10/05/PerformanceOfForeachVsListForEach.aspx). |
When to test? |
|testing| |
Simple question, really.
I've mentioned already that I'm a novice developer, but as I get into the rhythm of my first professional project, I'm trying to make sure I develop good habits as soon as possible.
But I've found that I often forget to test, put it off, or do a whole bunch of tests at the end of a build instead of one at a time.
So I'm wondering what rhythm you guys like to get into when working on large projects, and where testing fits into it. |
I would second [Jonathan's response](http://stackoverflow.com/questions/22988/form-post-doesnt-contain-textbox-data-aspnet-c#23012) I would check your databinding settings.
If you do not need ViewState for the textboxes (i.e. no postback occurs until form submit) then you should disable it.
It sounds like you are not having problems saving the data (since you said you have managed to get the control to read the _correct_ data back). Therefore, I would say the problem loads in your databinding code. |
Pull image blob from table and convert to native format using SSIS |
|ssis| |
I have an .net webforms front end that allows admin users to upload two .xls files for offline processing. As these files will be used for validation (and aggregation) I store these in an image field in a table.
My ultimate goal is to create a SSIS package that will process these files offline. Does anyone know how to use SSIS to read a blob from a table into it's native (in this case .xls) format for use in a Data Flow task? |
SSIS convert image blob |
I have a .net webforms front end that allows admin users to upload two .xls files for offline processing. As these files will be used for validation (and aggregation) I store these in an image field in a table.
My ultimate goal is to create a SSIS package that will process these files offline. Does anyone know how to use SSIS to read a blob from a table into it's native (in this case .xls) format for use in a Data Flow task? |
In order to do this I think you'd need to create a Cocoa application that was registered with OS X Launch Services as the default role handler for smb:// links.
I've written some stuff about how to do this on another question: [How do you set your Cocoa application as the default web browser?](http://stackoverflow.com/questions/49510/how-do-you-set-your-cocoa-application-as-the-default-web-browser#49512)
If there's a pure AppleScript solution or a way of only handling links within Mail.app I'm not aware of it. |
Andrew, (in addition to modeling as a pipeline etc), measuring things is important. Have you ran a profiler over the code and got metrics of where most of the time is spent?
For the database code, how often does it change ? Are you looking at caching at the moment ? I assume you have looked at indexes etc over the data to speed up the Db ?
What levels of traffic do you have on the front end ? Are you caching web pages ? (It isn't too hard to say use a JMS type api to communicate between components. You can then put Web Page component on one machine (or more), and then put the integration code (c++) on another, and for many JMS products there are usually native C++ api's ie. ActiveMQ comes to mind), but it really helps to know how much of the time is in Web (JSP ?) , C++, Database ops.
Is the database storing business data, or is it being also used to pass data between Java and C++ ? You say you are using shared mem not JNI ? What level of multi-threading currently exists in the APP? Would you describe the code as being synchronous in nature or async?
Is there a physical relationship between the Solaris code and the devices that must be maintained (ie. do all the devices register with the c++ code, or can that be specified). ie. if you were to put a web load balancer on the frontend, and just put 2 machines up today is the relationhip of which devices are managed by a box initialized up front or in advance?
What are the HA requirements ? ie. just state info ? Can the HA be done just in the web tier by clustering Session data ?
Is the DB running on another machine ?
How big is the DB ? Have you optimized your queries ie. tried using explicit inner/outer joins sometimes helps versus nested sub queries (sometmes). (again look at the sql stats).
|
At some point, something, somewhere is going to have to use Xml Deserialization, whether it is you or a wrapper inside the settings class. You could always abstract it away in a method to remove the "ugly" code from your business logic.
public static T FromXml<T>(string xml)
{
XmlSerializer xmlser = new XmlSerializer(typeof(T));
using (System.IO.StringReader sr = new System.IO.StringReader(xml))
{
return (T)xmlser.Deserialize(sr);
}
}
[http://www.vonsharp.net/PutDownTheXmlNodeAndStepAwayFromTheStringBuilder.aspx][1]
[1]: http://www.vonsharp.net/PutDownTheXmlNodeAndStepAwayFromTheStringBuilder.aspx |
Issue reading Xml file into C# DataSet |
|c#|.net|xml|.net-2.0| |
I was given an .xml file that I needed to read into my code as a DataSet (as background, the file was created by creating a DataSet in C# and calling dataSet.WriteXml(file, XmlWriteMode.IgnoreSchema), but this was done by someone else). The .xml file was shaped like this:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Foo>
<Bar>abcd</Bar>
<Foo>efg</Foo>
</Foo>
<Foo>
<Bar>hijk</Bar>
<Foo>lmn</Foo>
</Foo>
</NewDataSet>
Using C# and .NET 2.0, I read the file in using the code below.
DataSet ds = new DataSet();
ds.ReadXml(file);
Using a breakpoint, after this line ds.Tables[0] looked like this (using dashes in place of underscores that I couldn't get to format properly):
Bar Foo-Id Foo-Id-0
abcd 0 null
null 1 0
hijk 2 null
null 3 2
I have found a workaround (I know there are many) and have been able to successfully read in the .xml, but what I would like to understand why ds.ReadXml(file) performed in this manner, so I will be able to avoid the issue in the future. Thanks. |
My idea would be to query the titles like `SELECT title FROM articles` and simply check if each wikilink is in that array of strings. If it is you link to the page, if not, you link to the create page. |
Good reasons for not letting the browser launch local applications |
|security|internet-explorer|activex|intranet| |
I know this might be a no-brainer, but please read on.
I also know it's generally not considered a good idea, maybe the worst, to let a browser run and interact with local apps, even in a intranet context.
We use citrix for home-office, and people really like it. Now, they would like the same kind of environment at work, a nice page where every important application/document/folder is nicely arranged and classified in an orderly fashion. These folks are not particularly tech savvy; I don't even consider thinking that they could understand the difference between remote delivered applications and local ones.
So, I've been asked if it's possible. Of course it is, with IE's good ol' ActiveX controls. And I even made a working prototype (that's where it hurts).
But now, I doubt. Isn't it madness to allow such 'dangerous' ActiveX controls, even in the '*local intranet*' zone ? People will use the same browser to surf the web, can I fully trust IE ? Isn't there a risk that Microsoft would just disable those controls in future updates / versions ? What if a website, or any kind of malware, just puts another site in the trust list ? With that extent of control, you could as well uninstall every protection and just run amok 'till you got hanged by the IT dept.
I'm about to confront my superiors with the fact that, even if they saw it is doable, it would be a very bad thing. So i'm desperately in need of good and strong arguments, because "*let's don't*" won't do it.
Of course, if there is nothing to be scared of, that'll be nice too. But I strongly doubt that.. |
If you're currently using Authenticate, then you may already have an *htpasswd* file. If you would like to continue using that file, but switch to using FORM based authentication rather than via the Authenticate header, you can use a PHP script to use the same htpasswd file and use sessions to maintain the authentication status.
A quick Google search for php htpasswd reveals [this page][1] with a PHP function to check credentials against an htpasswd. You could integrate it (assuming you have sessions set to autostart) with some code like this:
// At the top of your 'private' page(s):
if($_SESSION['authenticated'] !== TRUE) {
header('Location: /login.php');
die();
}
// the target of the POST form from login.php
if(http_authenticate($_POST['username'], $_POST['password']))
$_SESSION['authenticated'] = TRUE;
[1]: http://koivi.com/php-http-auth/ |
using a html entity in xslt (e.g. ) |
|xslt| |
what is the best way to include a htlm entity in XSLT?
<xsl:template match="/a/node">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:template>
this one returns a **XsltParseError** |
Are there any examples where we *need* protected inheritance in C++ |
You could transform both into [timedelta objects](http://docs.python.org/lib/datetime-timedelta.html) and subtract these from each other, taking care to handle carry-overs correctly (from sec to min etc). |
I can't say enough about the Eclipse RCP platform. I would recommend it for any Java desktop app development.
It's free, has great tutorials, and allows cross-platform development of rich desktop applications that use native OS windowing toolkit, meaning that your application will look native in any platform. It also has a clean API that stays out of your way, and makes deploying to any platform a piece of cake.
If your interested check out this book: http://www.amazon.com/Eclipse-Rich-Client-Platform-Applications/dp/0321334612
|
If I understand correctly what you are trying to do, you can use the StringBuilder. Use the StringBuilder.Append method and append the XmlElement 'OuterXml' property.
For example:
sb.Append(xmlElement.OuterXml) |
Database system that is not relational. |
|database| |
What are the other types of database systems out there. I've recently came across couchDB that handles data in a non relational way. It got me thinking about what other models are other people is using.
So, I want to know what other types of data model is out there. (I'm not looking for any specifics, just want to look at how other people are handling data storage, my interest are purely academic)
The ones I already know are:
1. RDBMS (mysql,postgres etc..)
2. Document based approach (couchDB, lotus notes)
3. Key/value pair (BerkeleyDB) |
Firstly, note that a datetime.time is a time of day, independent of a given day, and so the different between any two datetime.time values is going to be less than 24 hours.
One approach is to convert both datetime.time values into comparable values (such as milliseconds), and find the difference.
t1, t2 = datetime.time(...), datetime.time(...)
t1_ms = (t1.hour*60*60 + t1.minute*60 + t1.second)*1000 + t1.microsecond
t2_ms = (t2.hour*60*60 + t2.minute*60 + t2.second)*1000 + t2.microsecond
delta_ms = max([t1_ms, t2_ms]) - min([t1_ms, t2_ms])
It's a little lame, but it works. |
[db4o][1]
Quote from the "about" page:
> db4o is the open source object database that enables Java and .NET developers to store and retrieve any application object with only one line of code, eliminating the need to predefine or maintain a separate, rigid data model.
[1]: http://www.db4o.com |
Subversion 1.5 introduces sparse checkouts which may be something you might find useful:
http://svnbook.red-bean.com/nightly/en/svn.advanced.sparsedirs.html
|
C++ - foo( void ) |
|c++|arguments| |
Consider these two function definitions
void foo(){}
void foo(void){}
Is there any difference between these two? If not, why is the void argument there? Aesthetic reasons?
|
Isn't Amazon's [SimpleDB](http://www.amazon.com/gp/browse.html?node=342335011) non-relational? |
If you want to unit test your WCF service classes make sure you design them with loose coupling in mind so you can mock out each dependancy as you only want to test the logic inside the service class itself.
For example, in the below service I break out my data access repository using "Poor Man's Dependency Injection".
Public Class ProductService
Implements IProductService
Private mRepository As IProductRepository
Public Sub New()
mRepository = New ProductRepository()
End Sub
Public Sub New(ByVal repository As IProductRepository)
mRepository = repository
End Sub
Public Function GetProducts() As System.Collections.Generic.List(Of Product) Implements IProductService.GetProducts
Return mRepository.GetProducts()
End Function
End Class
On the client you can mock the WCF service itself using the interface of the service contract.
<TestMethod()> _
Public Sub ShouldPopulateProductsListOnViewLoadWhenPostBackIsFalse()
mMockery = New MockRepository()
mView = DirectCast(mMockery.Stub(Of IProductView)(), IProductView)
mProductService = DirectCast(mMockery.DynamicMock(Of IProductService)(), IProductService)
mPresenter = New ProductPresenter(mView, mProductService)
Dim ProductList As New List(Of Product)()
ProductList.Add(New Product)
Using mMockery.Record()
SetupResult.For(mView.PageIsPostBack).Return(False).Repeat.Once()
Expect.Call(mProductService.GetProducts()).Return(ProductList).Repeat.Once()
End Using
Using mMockery.Playback()
mPresenter.OnViewLoad()
End Using
'Verify that we hit the service dependency during the method when postback is false
Assert.AreEqual(1, mView.Products.Count)
mMockery.VerifyAll()
End Sub |
You might also take a look at java channel for locking a part of a file.
[http://java.sun.com/javase/6/docs/api/java/nio/channels/FileChannel.html][1]
This function of the `FileChannel` might be a start
lock(long position, long size, boolean shared)
An invocation of this method will block until the region can be locked
[1]: http://java.sun.com/javase/6/docs/api/java/nio/channels/FileChannel.html |
People usually jump the technology bandwagon when there is a a real productivity to gain. Something to compensate for all the productivity loss that normally occurs when you adopt a new platform. WPF is just not there yet. It still takes more effort and more time to build a WPF app than a Forms app, and by a long shot.
Combine this with less documentation on the net about WPF than Windows Forms, less people with WPF experience, less blogs on WPF, less books on WPF, less tips/tricks,etc.
And don't get me started on XAML. Is it XML? is it a script? is it a code? Why did they decide that a hyperlink is just a label property? A lot of things still need to be ironed out there.
I cannot afford to build my next project in WPF, it will cost me a lot more to do it (in manpower and time), with nothing to show for in return. At the moment all we do in WPF is pure-research-inhouse-hobby projects. |
If you do build XML yourself, don't forget to escape the special characters. This tends to be overlooked, but can cause some serious headaches if it is not implemented:
* < &lt;
* > &gt;
* & &amp;
* " &quot;
* ' &apos; |
Can you try using a tool like [Fiddler][1] or [HttpWatch][2] and check if a request actually goes for the .css file from the login page. Verify the return codes are 200. Could be because of relative path issue in your dev box.
[1]: http://fiddler2.com/fiddler2/
[2]: http://httpwatch.com/ |
Start with a clean web.config and only add the sections you need.
For security, all you really can do is make sure you flag
<compelation debug="false">
for your production box and set custom errors to true. |
The compiler will allocate static variable(s) defined in a function <code>foo</code> at program load, however the compiler will also add some additional instructions (machine code) to your function <code>foo</code> so that the first time it is invoked this additional code will initialize the static variable (e.g. invoking the constructor, if applicable). |
The compiler will allocate static variable(s) defined in a function <code>foo</code> at program load, however the compiler will also add some additional instructions (machine code) to your function <code>foo</code> so that the first time it is invoked this additional code will initialize the static variable (e.g. invoking the constructor, if applicable).
@Adam: This behind the scenes injection of code by the compiler is the reason for the result you saw. |
I think you can do it be implementing the [IReadOnlySessionState][1] interface on your HttpHandler
[1]: http://www.hanselman.com/blog/GettingSessionStateInHttpHandlersASHXFiles.aspx |
CSS to increase size of first word |
|css| |
This one has me kind of stumped. I want to make the first word of all the paragraphs in my #content div at 14pt instead of the default for the paragraphs (12pt). Is there a way to do this in straight CSS or am I left wrapping the first word in a span to accomplish this? |
JDK 1.6_07+ contains an app called VisualVM (bin/jvisualvm.exe) that is a nice GUI on top of many of the tools. It seems more comprehensive than JConsole. |
You might be interested in Steve Gibson's over-the-top-secure implementation of a password generator (no source, but he has a detailed description of how it works) at [https://www.grc.com/passwords.htm][1].
[1]: https://www.grc.com/passwords.htm |
You might be interested in Steve Gibson's over-the-top-secure implementation of a password generator (no source, but he has a detailed description of how it works) at [https://www.grc.com/passwords.htm][1].
The site creates huge 64-character passwords but, since they're completely random, you could easily take the first 8 (or however many) characters for a less secure but "as random as possible" password.
[1]: https://www.grc.com/passwords.htm |
You might be interested in Steve Gibson's over-the-top-secure implementation of a password generator (no source, but he has a detailed description of how it works) at [https://www.grc.com/passwords.htm][1].
The site creates huge 64-character passwords but, since they're completely random, you could easily take the first 8 (or however many) characters for a less secure but "as random as possible" password.
EDIT: from your later answers I see you need something more like a GUID than a password, so this probably isn't what you want...
[1]: https://www.grc.com/passwords.htm |
|language|c++|inheritance| |
While I've seen rare cases where *private* inheritance was needed, I've never encountered a case where *protected* inheritance is needed. Does someone have an example? |
|language|c++|inheritance|oop| |
Are there any examples where we *need* protected inheritance in C++? |
|c++|oop|inheritance|language| |
\0 will also match the entire matched expression without doing an explicit capture using parenthesis.
preg_replace("/[A-Z]/", "<span class=\"initial\">\\0</span>", $str)
As always, you can go to [php.net/preg_replace][1] or php.net/<whatever search term> to search the documentation quickly. Quoth the documentation:
> \\0 or $0 refers to the text matched by the whole pattern.
[1]: http://php.net/preg_replace |
Unless technology has improved in ways I can't imagine of late, the "IN" query shown will produce a result that's effectively the OR-ing of three result sets, one for each of the values in the "IN" list. The IN clause becomes an equality condition for each of the list and will use an index if appropriate. In the case of unique IDs and a large enough table then I'd expect the optimiser to use an index.
If the items in the list were to be non-unique however, and I guess in the example that a "TypeId" is a foreign key, then I'm more interested in the distribution. I'm wondering if the optimiser will check the stats for each value in the list? Say it checks the first value and finds it's in 20% of the rows (of a large enough table to matter). It'll probably table scan. But will the same query plan be used for the other two, even if they're unique?
It's probably moot - something like an Employee table is likely to be small enough that it will stay cached in memory and you probably wouldn't notice a difference between that and indexed retrieval anyway.
And lastly, while I'm preaching, beware the query in the IN clause: it's often a quick way to get something working and (for me at least) can be a good way to express the requirement, but it's almost always better restated as a join. Your optimiser may be smart enough to spot this, but then again it may not. If you don't currently performance-check against production data volumes, do so - in these days of cost-based optimisation you can't be certain of the query plan until you have a full load and representative statistics. If you can't, then be prepared for surprises in production... |
> this one returns a **XsltParseError**
Yes, and the reason for that is that ` ` is not a predefined entity in XML or XSLT as it is in HTML.
You could just use the unicode character which ` ` stands for: ` ` |
Where do I use delegates? |
|design-patterns|tutorials|software-engineering| |
What are some real world places that call for delegates? I'm curious what situations or patterns are present where this method is the best solution. No code required. |
|design-patterns|tutorials|software-engineering|delegates| |
Do you have a specific scenario in mind?
For example, if the LOB holds files, and you are on a company intranet, perhaps you can write a stored procedure to extract the files to a known directory on the network and access them from there. |
[@ChanChan](#35595)
This is why a lot of companies store their applications' connection strings at the machine level instead of the application level.
Just take the connection string out of the source code entirely. Then have everyone put *their* connection string in *their* machine.config.
This has the added benefit of avoiding unnecessary app-specific environment logic, i.e. when you copy your application to the staging server, the staging server already "knows" what database to use.
Hope this helps. |
In a constructor, I don't think so. In a generic method though, you can use a limited form of type inferrence.
Example: if you have the function
<T> T getSomething() {
//...
}
you can use:
final String something = getsomething();
instead of:
final String something = <String>getsomething();
|
In a constructor, I don't think so. In a generic method though, you can use a limited form of type inferrence.
Example: if you have the function
<K, V> Map<K, V> getSomething() {
//...
}
you can use:
final Map<String, Object> something = getsomething();
instead of:
final Map<String, Object> something = this.<String, Object>getsomething();
|
In a generic method, you can use a limited form of type inferrence to avoid some repetitions.
Example: if you have the function
<K, V> Map<K, V> getSomething() {
//...
}
you can use:
final Map<String, Object> something = getsomething();
instead of:
final Map<String, Object> something = this.<String, Object>getsomething();
|
In this specific case can the only way the two systems can communicate is using the dblink.
Also, the table solution is not that terrible, it's just messy to have to "cache" the data on my side of the dblink. |
The `params` parameter modifer gives callers a shortcut syntax for passing multiple arguments to a method. There are two ways to call a method with a `params` parameter:
1) Calling with an array of the parameter type, in which case the `params` keyword has no effect and the array is passed directly to the method:
object[] array = new[] { "1", "2" };
// Foo receives the 'array' argument directly.
Foo( array );
2) Or, calling with an extended list of arguments, in which case the compiler will automatically wrap the list of arguments in a temporary array and pass that to the method:
// Foo receives a temporary array containing the list of arguments.
Foo( "1", "2" );
// This is equivalent to:
object[] temp = new[] { "1", "2" );
Foo( temp );
<br/>
In order to pass in an object array (i.e. "`object[] array = new[] { "1", "2" };`") to a method with a "`params object[]`" parameter, you can either:
1) Create a wrapper array manually and pass that directly to the method, as mentioned by [lassevk](http://stackoverflow.com/questions/36350/c-how-to-pass-a-single-object-to-a-params-object#36360):
Foo( new object[] { array } );
2) Or, cast the argument to `object`, as mentioned by [Adam](http://stackoverflow.com/questions/36350/c-how-to-pass-a-single-object-to-a-params-object#36367), in which case the compiler will create the wrapper array for you:
Foo( (object)array );
<br/>
However, if the goal of the method is to process multiple object arrays, it may be easier to declare it with an explicit "`params object[][] arrays` parameter. This would allow you to pass multiple arrays as arguments:
object[] array1 = new[] { "1", "2" };
object[] array2 = new[] { "3", "4" };
// Foo will receive an object[][] containing 'array1'.
Foo( array1 );
// Foo will receive an object[][] containing both 'array1' and 'array2'.
Foo( array1, array2 );
...
void Foo( params object[][] arrays ) {
foreach( object[] array in arrays ) {
// process array
}
}
|
Process.TotalProcessorTime
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.totalprocessortime.aspx |
Name of the process with highest cpu usage |
|performance|operating-system| |
I have a [Samurize](http://www.samurize.com/modules/news/) config that shows a CPU usage graph similar to Task manager.
How do I also display the name of the process with the current highest CPU usage percentage?
I would like this to be updated, at most, once per second. Samurize can call a command line tool and display it's output on screen, so this could also be an option. |
|windows|performance|operating-system| |
As WMR mentioned, IOUtils from apache has a method called copy which does exactly what you're looking for.
So, you have <br/>
<b><code>IOUtils.copy(in,out);</code></b>
<br/> in your code.
Is there a reason you're avoiding IOUtils? |
I agree with not running Office on a server. Not that I have any choice in the matter :)
One thing to keep in mind with the taskkill option, is that unless you specifically plan for it (aka - singleton), you may have multiple copies of Excel (or any other Office app) running, and unintentionally close the wrong instance.
Also note that per [http://support.microsoft.com/kb/257757][1]
> Microsoft does not currently
> recommend, and does not support,
> Automation of Microsoft Office
> applications from any unattended,
> non-interactive client application or
> component (including ASP, ASP.NET,
> DCOM, and NT Services), because Office
> may exhibit unstable behavior and/or
> deadlock when Office is run in this
> environment.
As an alternative, there is a product called [Aspose Cells][2] that offers a product that is designed to allow you to programmatically work with an Excel sheet in a server environment. As a disclaimer, I have never personally used this product, but I have heard about it from several people I worked with in the past.
[1]: http://support.microsoft.com/kb/257757
[2]: http://www.aspose.com/categories/file-format-components/aspose.cells-for-.net-and-java/default.aspx |
The idea of wrapping that up the functionality in some sort of manager is always nice. It allows for better testing, and management therefore of schema changes.
Also allows for easier reuse in the application. NEVER just put the sql in directly!!!. For Hibernate I have found HQL great for just this. In particular , if you can use Named queries. Also be careful of adding an filter values etc use "string append", use parameters (can we say SQL injection ?). Even if the SQL is dynamic in terms of the join or where criteria, have a function in some sort of manager is always best. |
We have a situation that sounds similar to yours.
We use separate objects for reporting data that spans several domain objects. Our convention is that these will be backed by a view in the database, so we have come to call them view objects. We generally use them for summarising complex data into a flat format. |