instruction stringlengths 0 30k ⌀ |
|---|
Make methods static when they are not part of the instance. Don't sweat the micro-optimisations.
You might find you have lots of private methods that could be static but you always call from instance methods (or each other). In that case it doesn't really matter that much. However, if you want to actually be able to test your code, and perhaps use it from elsewhere, you might want to consider making those static methods in a different, non-instantiable class. |
Whether or not a method is static is more of a design consideration than one of efficiency. A static method belongs to a class, where a non-static method belongs to an object. If you had a Math class, you might have a few static methods to deal with addition and subtraction because these are concepts associated with Math. However, if you had a Car class, you might have a few non-static methods to change gears and steer, because those are associated with a specific car, and not the concept of cars in general. |
In the end it all boils down to the protocol you'd want to use. Shoutcast IMHO is plain HTTP, so to *make* your own stream, you just output the streams content.
To make an ogg based webradio work with my Sonos system, I have created a little transcoding wrapper around sox which is is actually written in PHP, so it may be helpful to you to serve as an example.
You'll find it here: http://www.gnegg.ch/ogg2mp3/
If you are after implementing your very own streaming protocol - maybe even UDP based, then, I'm afraid, PHP may not be the right solution for the problem - at least not as long as it has its share of problems when used for long running processes (which 5.3 may bring some help for with its integrated garbage collection) |
I found this book by keith Brown The .NET Developer's Guide to Windows Security. It has some good samples covering all kinds of security scenarios.
[Online version][1] is also available.
[1]: http://alt.pluralsight.com/wiki/default.aspx/Keith.GuideBook.HomePage |
The best strategy is always to give your users options. Why don't you start the stream at a low bitrate that will work for everyone and provide a "High Quality" link for those of us with FTTH connections? I believe YouTube has started doing this. |
p1.py:
<pre><code>
execfile("p2.py")
</code></pre>
p2.py:
<pre><code>
import inspect
print inspect.getfile( inspect.currentframe() )
</code></pre>
|
I don't think it will become mainstream. I think Ted Dziuba gets it right when he says it solves a "problem" that most people don't consider to be worth solving.
http://teddziuba.com/2008/09/openid-is-why-i-hate-the-inter.html |
If it were me, I'd reverse the question and ask why *I should* use a GridView, If you need a bunch of built-in features like paging and sorting, then the GridView might be a good fit. If you just want tabular data, I'd reconsider. Why? Because with GridView you're getting a whole bunch of stuff you won't use, your ViewState will be potentially huge, and your page performance will be slower.
I'm not a bigot when it comes to GridView, but I only use them when there is a damn good reason. |
Try attacking it from the other angle. Look at streaming services that cater to the customer you want, and have significant volume (maybe youtube) and see what they're pushing. You'll find there'a pretty direct correlation between alexa rating (popularity) and quality(minimum bitrate required). Vimeo will always have fewer users than Youtube because the user experience is poor for low bitrate users.
There are many other factors, and this should only form one small facet of your bandwidth decision, but it's a useful comparison to make.
Keep in mind, however, that you want to degrade gracefully. As more and more sites come online you'll start bumping into ISPs that limit total transfer, and being able to tell your customers how much of their bandwidth your site is consuming is useful, as well as proclaiming that you are a low bandwidth site.
Further, more and more users are using portable cellular connections (iPhone) where limited bandwidth is a big deal. AT&T has oversold many markets so being able to get useful video through a tiny link will enable you to capture market that vimeo and Hulu cannot.
Quite frankly, though, the best thing to do is degrade on the fly gracefully. Measure the bandwidth of the connection continuously and adjust bandwidth as needed for a smooth playback experience with good audio. Then you can take all users across the gamut...
-Adam |
In your above scenario, you'd be better off doing a master-detail style GridView, which will save you the overhead of all those GridView objects that get created.
There are various implementation of it ([using a drop down for the master][1], using a [modal popup for the detail][2], etc.), but the main point is that there are implementations available.
[1]: http://msdn.microsoft.com/en-us/library/aa479344.aspx
[2]: http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html |
Search by hash? |
|search|hash|utilities| |
I had the idea of a search engine that would index web items like other search engines do now but would only store the file's title, url and a hash of the contents.
This way it would be easy to find items on the web if you already had them and didn't know where they came from or wanted to know all the places that something appeared.
More useful for non textual items like images, executables and archives.
I was wondering if there is already something similar? |
|apache-flex|drag-and-drop| |
YUI drag&drop proxy drag |
|yui|dragdrop| |
Question for YUI experts...
I have a table and I've made each cell of the first row draggable by [proxy][1]. In IE, when the drag proxy is released, the original table cell actually jumps to wherever the release point was. How can I prevent this from happening? Essentially, I want to know where the proxy was dropped and handle my logic from there but I don't want the original to move.
[1]: http://developer.yahoo.com/yui/examples/dragdrop/dd-proxy.html |
|javascript|dragdrop|yui| |
|javascript|drag-and-drop|yui| |
MAPI and managed code experiences? |
|.net|mapi|pinvoke|e-mail| |
Using MAPI functions from within managed code is officially unsupported. Apparently, MAPI uses its own memory management and it crashes and burns within managed code (see [here](http://blogs.msdn.com/pcreehan/archive/2007/05/04/what-does-unsupported-mean.aspx) and [here](http://blogs.msdn.com/mstehle/archive/2007/10/03/fyi-why-are-mapi-and-cdo-1-21-not-supported-in-managed-net-code.aspx))
(But) I won't be fiddling with the advanced stuff such as opening an exchange mailbox or automatically sending mail on user's behalf. All I want to do is launch the default e-mail client with subject, body, AND one or more attachments.
So I've been looking into [MAPISendDocuments](http://pinvoke.net/default.aspx/mapi32.MAPISendDocuments) and it seems to work. But I haven't been able to gather courage to actually use the function in production code.
Has anybody used this function a lot? Do you have any horror stories?
*PS. No, I won't shellExecute Outlook.exe with command line arguments for attachments.* |
Using MAPI functions from within managed code is officially unsupported. Apparently, MAPI uses its own memory management and it crashes and burns within managed code (see [here](http://blogs.msdn.com/pcreehan/archive/2007/05/04/what-does-unsupported-mean.aspx) and [here](http://blogs.msdn.com/mstehle/archive/2007/10/03/fyi-why-are-mapi-and-cdo-1-21-not-supported-in-managed-net-code.aspx))
**All I want to do is launch the default e-mail client** with subject, body, **AND one or more attachments**.
So I've been looking into [MAPISendDocuments](http://pinvoke.net/default.aspx/mapi32.MAPISendDocuments) and it seems to work. But I haven't been able to gather courage to actually use the function in production code.
Has anybody used this function a lot? Do you have any horror stories?
*PS. No, I won't shellExecute Outlook.exe with command line arguments for attachments.* |
|.net|e-mail|pinvoke|mapi| |
|.net|email|mapi|pinvoke| |
|.net|pinvoke|e-mail|mapi| |
|.net|mapi|pinvoke|e-mail| |
|.net|email|pinvoke|mapi| |
I am using a wxGenericDirCtrl, and I would like to know if there is a way to hide directories, I'd especially like to hide siblings of parent nodes.
For example if my directory structure looks like this:
+-a
|
+-b
| |
| +-whatever
|
+-c
| |
| +-d
| |
| +-e
| |
| +-f
|
+-g
|
+-whatever
If my currently selected directory is /a/c/d is there any way to hide b and g, so that the tree looks like this in my ctrl:
+-a
|
+-c
|
+-[d]
|
+-e
|
+-f
I'm currently working with a directory structure that has lots and lots directories that are irrelevant to most users, so it would be nice to be able to clean it up.
|
I am using a wxGenericDirCtrl, and I would like to know if there is a way to hide directories, I'd especially like to hide siblings of parent nodes.
For example if my directory structure looks like this:
+-a
|
+-b
| |
| +-whatever
|
+-c
| |
| +-d
| |
| +-e
| |
| +-f
|
+-g
|
+-whatever
If my currently selected directory is /a/c/d is there any way to hide b and g, so that the tree looks like this in my ctrl:
+-a
|
+-c
|
+-[d]
|
+-e
|
+-f
I'm currently working with a directory structure that has lots and lots directories that are irrelevant to most users, so it would be nice to be able to clean it up.
**Edit**:
If it makes a difference, I am using wxPython, and so far, I have only tested my code on linux using the GTK backend, but I do plan to make it multi-platform and using it on Windows and Mac using the native backends. |
Yes, as Kevin says, HTTP/1.1 specifications say "A single-user client should not maintain more than 2 connections with any server or proxy." |
What do you use to create a website architecture? |
|html|architecture|project-planning| |
Sure, we can use a simple bulleted list or a mindmap. But, there must be a better, more interactive way. What do you use when starting your website architecture? |
|architecture|project-planning| |
By "architecture", do you mean the initial site map? If not, please post a clarification and I'll edit my response.
Our tech team starts development after our creative department has done their stuff. Part of what we get is output from the information architect. He passes off a graphical sitemap, a detailed sitemap as an Excel sheet, and a set of wireframes in a PDF. |
CakePHP ACL Database Setup: ARO / ACO structure? |
|cakephp|acl| |
I'm struggling to implement ACL in CakePHP. After reading the documentation in the [cake manual][1] as well as several other tutorials, blog posts etc, I found Aran Johnson's excellent tutorial which has helped fill in many of the gaps. His examples seem to conflict with others I've seen though in a few places - specifically in the ARO tree structure he uses.
In his [examples][2] his user groups are set up as a cascading tree, with the most general user type being at the top of the tree, and its children branching off for each more restricted access type. Elsewhere I've usually seen each user type as a child of the same generic user type.
How do you set up your AROs and ACOs in CakePHP? Any and all tips appreciated!
[1]: http://manual.cakephp.org/view/171/Access-Control-Lists
[2]: http://aranworld.com/article/169/acl-and-auth-tutorial-database-setup |
The cause of your problem is **NOT** the Win console not willing to accept Unicode (as it does this since I guess Win2k by default). It is the default system encoding. Try this code and see what it gives you:
import sys
sys.getdefaultencoding()
if it says ascii, there's your cause ;-)
You have to create a file called sitecustomize.py and put it under python path (I put it under /usr/lib/python2.5/site-packages, but that is differen on Win - it is c:\python\lib\site-packages or something), with the following contents:
import sys
sys.setdefaultencoding('utf-8')
and perhaps you might want to specify the encoding in your files as well:
# -*- coding: UTF-8 -*-
import sys,time
Edit: more info can be found [in excellent the Dive into Python book][1]
[1]: http://www.diveintopython.org/xml_processing/unicode.html |
You will generate a key on the users machine via whatever ssh client they are using. pUTTY for example has a utility to do this exact thing. It will generate both a private and public key.
The contents of the public key file generated will be placed in the authorized_keys file.
Next you need to make sure that the ssh client is configured to use the private key that generated the public key. It's fairly straight forward, but slightly different depending on the client being used. |
You don't actually have to use the generated class that the WSDL gives you. If you take a look at the code that it generates, it's just making calls into some .NET framework classes to submit SOAP requests. In the past I have copied that code into a normal .cs file and edited it. Although I haven't tried this specifically, I see no reason why you couldn't drop the proxy class definition and use the original class to receive the results of the SOAP call. It must already be doing reflection under the hood, it seems a shame to do it twice. |
GateKiller,
In simple terms (and not a copy-paste out of the SQLBOL) so you can understand the concepts:
RESTORE WITH RECOVERY uses the backup media file (eg. fulldata.bak) to restore the database to back to the time that backup file was created. This is great if you want to go back in time to restore the database to an earlier state - like when developing a system.
If you want to restore the database TO THE VERY LATEST DATA, (i.e. like if your doing a system Disaster Recovery and you cannot lose any data) then you want to restore that backup AND THEN all the transaction logs created since that backup. This is when you use RESTORE NORECOVERY. It will allow you to restore the later transaction logs right up to the point of failure (as long as you have them).
RECOVERY WITH STANDBY is the ability to restore the database up to a parital date (like NORECOVERY above) but to allow the database still to be used READONLY. New transaction logs can still be applied to the database to keep it up to date (a standby server). Use this when it would take too long to restore a full database in order to Return To Operations the system. (ie. if you have a multi TB database that would take 16 hours to restore, but could receive transaction log updates every 15 minutes).
This is a bit like a mirror server - but without having "every single transaction" send to the backup server in real time. |
Call ASP.NET Function From Javascript? |
[According to CWA][1], the average US resident has a 1.9Mbps download speed. They have data by state, so if you have money then you can probably get a more specific report for your intended audience. Keep in mind, however, that more and more people are sharing this with multiple computers, using VOIP devices, and running background processes that consume bandwidth.
-Adam
[1]: http://arstechnica.com/news.ars/post/20070529-survey-average-broadband-speed-in-us-is-1-9mbps.html |
I've used the following in a header file occasionally to produce clickable items in
the VC6 and recent VS(2003+) compiler ouptut window.
Basically, this exploits the fact that items output in the compiler output
are essentially being parsed for "PATH(LINENUM): message".
This presumes on the Microsoft compiler's treatment of "pragma remind".
This isn't quite exactly what you asked... but it might be generally helpful
in arriving at something you can get the compiler to emit that some editors might honor.
<pre>
// The following definitions will allow you to insert
// clickable items in the output stream of the Microsoft compiler.
// The error and warning variants will be reported by the
// IDE as actual warnings and errors... which means you can make
// them occur in the task list.
// In theory, the coding standards could be checked to some extent
// in this way and reminders that show up as warnings or even
// errors inserted...
#define strify0(X) #X
#define strify(X) strify0(X)
#define remind(S) message(__FILE__ "(" strify( __LINE__ ) ") : " S)
// example usage
#pragma remind("warning: fake warning")
#pragma remind("error: fake error")
</pre>
I haven't tried it in a while but it should still work. |
I should had used google.
\\\
#If DEBUG Then
Console.WriteLine("Debug mode.")
#Else
Console.WriteLine("Release mode.")
#End If
///
Make sure that the option "Configuration settings" -> "Build" "Define DEBUG
constant" in the project properties is checked.
|
Compiler constants. I don't remember the C# syntax, but this is how I do it in VB:
#If CONFIG = "Debug" Then
'do somtehing
#Else
'do something else
#EndIf |
Well, for images, there's [http://tineye.com/][1], which will one-up that, and find you similar images too.
[1]: http://tineye.com/ tin eye |
>>> import weakref
>>> class Object:
... pass
...
>>> o = Object()
>>> r = weakref.ref(o)
>>> # if the reference is still active, r() will be o, otherwise None
>>> do_something_with_o(r())
See the [wearkref module docs][1] for more details.
You can also use `weakref.proxy` to create an object that proxies o. Will throw `ReferenceError` if used when the referent is no longer referenced.
[1]: http://docs.python.org/lib/module-weakref.html |
Redirecting non-www URL to www |
|.htaccess|isapi-rewrite| |
I'm using [Helicon's ISAPI Rewrite 3][1], which basically enables .htaccess in IIS. I need to redirect a non-www URL to the www version, i.e. example.com should redirect to www.example.com. I used the following rule from the examples but it affects subdomains:
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]
This works for most part, but is also redirect sub.example.com to www.sub.example.com. How can I rewrite the above rule so that subdomains do not get redirected?
[1]: http://www.helicontech.com/isapi_rewrite/ |
I found this book by keith Brown The .NET Developer's Guide to Windows Security. It has some good samples covering all kinds of security scenarios.
Free [Online version][1] is also available.
[1]: http://alt.pluralsight.com/wiki/default.aspx/Keith.GuideBook.HomePage |
Adding extra information to a custom exception |
|c#|.net|exception|elmah| |
I've created a custom exception for a very specific problem that can go wrong. I receive data from another system, and I raise the exception if it bombs while trying to parse that data. In my custom exception, I added a field called "ResponseData", so I can track exactly what my code couldn't handle.
In custom exceptions such as this one, should that extra response data go into the exception "message"? If it goes there, the message could be huge. I kind of want it there because I'm using Elmah, and that's how I can get at that data.
So the question is either:
- How can I get Elmah to record extra information from a field in a custom exception
OR
- Should extra exception details go into the "message" property? |
Boolean Expressions in Shell Scripts |
|bash|shell|expression| |
What's the "right" way to do the following as a boolean expression?
for i in `ls $1/resources`; do
if [ $i != "database.db" ]
then
if [ $i != "tiles" ]
then
if [ $i != "map.pdf" ]
then
if [ $i != "map.png" ]
then
svn export -q $1/resources/$i ../MyProject/Resources/$i
...
|
Since you're not going to have a user interacting with the program, I'd say make configuration variable (in an app.config file) responsible for sending/not sending the data. That way users who don't want to report errors can just change a flag in a config file. I'd personally have it turned on by default and then give them guidance on how to turn it off it they wanted to. |
create table question_bank
(
question_id uniqueidentifier primary key,
question_exam_id uniqueidentifier not null,
question_text varchar(1024) not null,
question_point_value decimal,
foreign key ( question_exam_id ) references exams (exam_id)
); |
I work for one of those consulting firms mentioned by Carlton, and let me tell you that we are the only company to have developed an in-house (proprietary) tool that helps us jump start the conversion process from RPTs to RDLs. Our current tool only supports Crystal Rpts 9 and older, and the RDL 2000 and 2005 formats.
I have done several of these conversion projects myself, and there are lots of things that cannot be automatically converted due to the nature of each product. Things like expressions, data source information, and dataset queries just cannot be automagically "translated" by a tool.
Cheers. |
According to the [Mono roadmap][1] I'm not sure if Linq is available for mono?
At least some of Linq might be available in the very latest release, but Linq to DB is listed for Mono 2.4 (Feb 2009)
[1]: http://www.mono-project.com/Mono_Project_Roadmap |
|javascript|asp.net| |
I'm writing a web page in ASP.NET. I have some Javascript, and I have a submit button with an onClick event.
Is it possible to call a method I created in ASP with Javascript's onCall event? |
I'm writing a web page in ASP.NET. I have some Javascript, and I have a submit button with an onClick event.
Is it possible to call a method I created in ASP with Javascript's onClick event? |
|c#|asp.net|javascript| |
SQL Server Recpvery States |
|sql|backup| |
When restoring a SQL Server Database, I notice that there are 3 different Recovery States to choose from:
- Restore with Recovery
- Restore with No Recovery
- Restore with Standby
I've always left it at it's default value, but what do they all mean?
(Preferably in layman's terms) |
SQL Server Recovery States |
You might want to check out [Subsonic][1]. It is an ORM that uses an ActiveRecord pattern. I'm pretty sure most of its features work with the .NET Framework 2.0.
[1]: http://subsonicproject.com/ |
You might want to create a web service for your common methods.
Just add a WebMethodAttribute over the functions you want to call, and that's about it.
Having a web service with all your common stuff also makes the system easier to maintain. |
@[Jason Day][1], I think the 4 in the last %4s is significant if there are fewer than 4 characters. If there are more than 4 you are right, %4s and %s would be the same, but with fewer than 4 chars in g %s would be left justified and %4s would be right-justified in a 4 char field.
b is actually minimum 16 chars for the whole field, including the decimal and the single digit after the decimal I think (16 total chars vs 18 total chars)
[1]: http://stackoverflow.com/questions/7981/decoding-printf-statements-in-c-printf-primer#8035 |
One problem I can see is that, in a large company, this pattern could allow the code to become difficult (if not impossible) for anyone to understand and use. If multiple developers are constantly adding their own methods to existing classes, separate from those classes (and, God help us all, to BCL classes even), I could see a code base spinning out of control rather quickly.
Even at my own job, I could see this happening, with my PM's desire to add every bit of code that we work on to either the UI or the data access layer, I could totally see him insisting on 20 or 30 methods being added to System.String that are only tangentially-related to string handling. |
Actually nlucaroni, your case isn't quite right. Your example doesn't include double-quotes, so
id,age,name,...
1,23,phil,
won't match my regex. It requires the format "XXX,XXX". I can't think of an example of when it will match incorrectly.
All the following example won't include the deliminator in the regex:
> "111,111",234
> 234,"111,111"
> "111,111","111,111"
Please let me know if you can think of a counter-example.
Cheers! |
This is not specific to any language, it´s just about best practices. I am using JPA/Hibernate (but it could be any other ORM solution) and I would like to know how do you guys deal with this situation:
Let´s supose that you have a query returning something that is not represented by any of your domain classes.
Do you create a specific class to represent that specific query?
Do you return the query in some other kind of object (array, map...)
Some other solutions?
I would like to know about your experiences and best practices.
P.S.
Actually I am creating specific objetcs for specific queries. |
(N)Hibernate - is it possible to dynamically map multiple tables to the one class |
|c#|nhibernate|orm|hibernate|gis| |
I have the situation where i use GIS software which stores the information about GIS objects into separate database table for each type/class of GIS object (road, river, building, sea, ...) and keeps the metadata table in which it stores info about the class name and its DB table.
Those GIS objects of different classes share some parameters, i.e. Description and ID. I'd like to represent all of these different GIS classes with one common C# class (let's call it GisObject), which is enough for what i need to do from the non-GIS part of the application which lists GIS objects of the given GIS class.
The problem for me is how to map those objects using NHibernate to explain to the NHibernate when creating a C# GisObject to receive and **use the table name as a parameter** which will be read from the meta table (it can be in two steps, i can manually fetch the table name in first step and then pass it down to the NHibernate when pulling GisObject data).
Has anybody dealt with this kind of situation, and can it be done at all? |
Maybe try [campfire][1] or [basecamp][2].
[1]: http://www.campfirenow.com/
[2]: http://www.basecamphq.com/
|
this is VB.NET code to check for any removable drives or CDRom drives attached to the computer:
Me.lstDrives.Items.Clear()
For Each item As DriveInfo In My.Computer.FileSystem.Drives
If item.DriveType = DriveType.Removable Or item.DriveType = DriveType.CDRom Then
Me.lstDrives.Items.Add(item.Name)
End If
Next
it won't be that hard to modify this code into a c# equivalent, and more *driveType*'s are available.
[From MSDN:][1]
- **Unknown:** The type of drive is unknown.
- **NoRootDirectory:** The drive does not have a root directory.
- **Removable:** The drive is a removable storage device, such as a floppy disk drive or a USB flash drive.
- **Fixed:** The drive is a fixed disk.
- **Network:** The drive is a network drive.
- **CDRom:** The drive is an optical disc device, such as a CD or DVD-ROM.
- **Ram:** The drive is a RAM disk.
[1]: http://msdn.microsoft.com/en-us/library/system.io.drivetype.aspx |
[JUNG][1] is a good option for visualisation, and also has a fairly good set of available graph algorithms, including several different mechanisms for random graph creation, rewiring, etc. I've also found it to be generally fairly easy to extend and adapt where necessary.
[1]: http://jung.sourceforge.net/ |
Cross-platform space remaining on volume using python |
Using MAPI functions from within managed code is officially unsupported. Apparently, MAPI uses its own memory management and it crashes and burns within managed code (see [here](http://blogs.msdn.com/pcreehan/archive/2007/05/04/what-does-unsupported-mean.aspx) and [here](http://blogs.msdn.com/mstehle/archive/2007/10/03/fyi-why-are-mapi-and-cdo-1-21-not-supported-in-managed-net-code.aspx))
**All I want to do is launch the default e-mail client** with subject, body, **AND one or more attachments**.
So I've been looking into [MAPISendDocuments](http://pinvoke.net/default.aspx/mapi32.MAPISendDocuments) and it seems to work. But I haven't been able to gather courage to actually use the function in production code.
Has anybody used this function a lot? Do you have any horror stories?
*PS. No, I won't shellExecute Outlook.exe with command line arguments for attachments.*
*PPS. Attachment support is a* requirement *, so Mailto: solutions do not cut it for me.* |
System.Web.Caching vs. Enterprise Library Caching Block |
|caching|.net-2.0|enterpriselibrary| |
For a .NET component that will be used in both web applications and rich client applications, there seem to be two obvious options for caching: System.Web.Caching or the Ent. Lib. Caching Block.
- What do you use?
- Why?
## [System.Web.Caching](http://msdn.microsoft.com/en-us/library/system.web.caching.aspx)
Is this safe to use outside of web apps? I've seen mixed information, but I think the answer is maybe-kind-of-not-really.
- [a KB article warning against 1.0 and 1.1 non web app use](http://support.microsoft.com/kb/917411)
- The 2.0 page has a *comment* that indicates it's OK: <http://msdn.microsoft.com/en-us/library/system.web.caching.cache(VS.80).aspx>
- [Scott Hanselman is creeped out by the notion](http://www.hanselman.com/blog/UsingTheASPNETCacheOutsideOfASPNET.aspx)
- [The 3.5 page](http://msdn.microsoft.com/en-us/library/system.web.caching.cache.aspx) includes a warning against such use
- Rob Howard [encouraged use outside of web apps](http://weblogs.asp.net/cschittko/archive/2004/07/04/172684.aspx)
I don't expect to use one of its highlights, [SqlCacheDependency](http://msdn.microsoft.com/en-us/library/system.web.caching.sqlcachedependency.aspx), but the addition of [CacheItemUpdateCallback](http://msdn.microsoft.com/en-us/library/system.web.caching.cacheitemupdatecallback.aspx) in .NET 3.5 seems like a Really Good Thing.
## [Enterprise Library Caching Application Block](http://msdn.microsoft.com/en-us/library/aa480453.aspx)
- other blocks are already in use so the dependency already exists
- cache persistence isn't necessary; regenerating the cache on restart is OK
Getting a callback *after* an item has been removed is not very convenient for cache items that ought to be available all the time. It looks like a client will have to just sleep and poll until the cache item is repopulated.
|
|.net-2.0|caching|enterpriselibrary| |
|.net-2.0|caching|memcached|enterpriselibrary| |
|.net-2.0|caching|enterprise-library|memcached| |
For a .NET component that will be used in both web applications and rich client applications, there seem to be two obvious options for caching: System.Web.Caching or the Ent. Lib. Caching Block.
- What do you use?
- Why?
## [System.Web.Caching](http://msdn.microsoft.com/en-us/library/system.web.caching.aspx)
Is this safe to use outside of web apps? I've seen mixed information, but I think the answer is maybe-kind-of-not-really.
- [a KB article warning against 1.0 and 1.1 non web app use](http://support.microsoft.com/kb/917411)
- The 2.0 page has a *comment* that indicates it's OK: <http://msdn.microsoft.com/en-us/library/system.web.caching.cache(VS.80).aspx>
- [Scott Hanselman is creeped out by the notion](http://www.hanselman.com/blog/UsingTheASPNETCacheOutsideOfASPNET.aspx)
- [The 3.5 page](http://msdn.microsoft.com/en-us/library/system.web.caching.cache.aspx) includes a warning against such use
- Rob Howard [encouraged use outside of web apps](http://weblogs.asp.net/cschittko/archive/2004/07/04/172684.aspx)
I don't expect to use one of its highlights, [SqlCacheDependency](http://msdn.microsoft.com/en-us/library/system.web.caching.sqlcachedependency.aspx), but the addition of [CacheItemUpdateCallback](http://msdn.microsoft.com/en-us/library/system.web.caching.cacheitemupdatecallback.aspx) in .NET 3.5 seems like a Really Good Thing.
## [Enterprise Library Caching Application Block](http://msdn.microsoft.com/en-us/library/aa480453.aspx)
- other blocks are already in use so the dependency already exists
- cache persistence isn't necessary; regenerating the cache on restart is OK
Getting a callback *after* an item has been removed is not very convenient for cache items that ought to be available all the time (but refreshed periodically). It looks like a client will have to just sleep and poll until the cache item is repopulated.
|
|php|cakephp|permissions|acl| |
Is this what you are looking for?
private List<ErrorItem<object>> _allObjects = new List<ErrorItem<object>>();
public IEnumerable<ErrorItem<A>> ItemsOfA
{
get
{
foreach (ErrorItem<object> obj in _allObjects)
{
if (obj.Item is A)
yield return new ErrorItem<A>((A)obj.Item, obj.MetaData);
}
}
}
If you want to cache the `ItemsOfA` you can easily do that:
private List<ErrorItem<A>> _itemsOfA = null;
public IEnumerable<ErrorItem<A>> ItemsOfACached
{
if (_itemsOfA == null)
_itemsOfA = new List<ErrorItem<A>>(ItemsOfA);
return _itemsOfA;
} |
<code><pre>
\#include <string>
\#include <boost/next_prior.hpp>
void reverse(std::string& foo) {
using namespace std;
reverse(foo.begin(), foo.end());
string::iterator begin = foo.begin();
while (1) {
std::string::iterator space = find(begin, foo.end(), ' ');
std::reverse(begin, space);
begin = boost::next(space);
if (space == foo.end())
break;
}
}</pre></code> |
<code><pre>
\#include <string>
\#include <boost/next_prior.hpp>
void reverse(std::string& foo) {
using namespace std;
std::reverse(foo.begin(), foo.end());
string::iterator begin = foo.begin();
while (1) {
string::iterator space = find(begin, foo.end(), ' ');
std::reverse(begin, space);
begin = boost::next(space);
if (space == foo.end())
break;
}
}</pre></code> |
Sarcastic's reply is so much better than mine, but if you were working with filesystem paths, my **ugly hack below** could turn out to be useful too. (Translation: I typed it, so I'll be damned if I don't post it :)
Path.Combine just slaps two strings together, paying attention to leading or trailing slashes. As far as I know, the only Path method that does normalization is Path.GetFullPath. The following will give you the "cleaned up" version.
myPath = System.IO.Path.GetFullPath(myPath);
Of course, there is the small issue that the resulting path will be rooted and the forward slashes will be converted to back slashes (like "C:\foo\bar\path.aspx"). But if you know the parent root of the original path, stripping out the root should not be a big problem. |
Tracking Refactorings in a Bug Database |
|refactoring|bug-tracking| |