instruction stringlengths 0 30k ⌀ |
|---|
The [Prologue theme][1] for WordPress was designed with this in mind.
[1]: http://en.blog.wordpress.com/2008/01/28/introducing-prologue/ |
In ATL these attributes were a compiler trick. They were not a core part of the platform like attributes in C#. They were also more confusing to debug than macros's and the method of dumping generated attribute code was a hassle.
I suspect another issue is likely to have been C++ compiler compatibility and standards-adherence. Attributes didn't make for more beautiful C++ code, and perhaps this syntax may be used in a future version of a real C++ standard. |
db4o, as mentioned by Eric, is an [Object-Oriented database management system][1] (OODBMS).
[1]: http://en.wikipedia.org/wiki/Object_database |
I think <http://hasno.info/2006/12/14/ruby-gotchas-and-caveats> has a decent explanation of the difference:
> catch/throw are not the same as raise/rescue. catch/throw allows you to quickly exit blocks back to a point where a catch is defined for a specific symbol, raise rescue is the real exception handling stuff involving the Exception object. |
A test confirms that GCC 4.2.3 will simply compare with the overflowed result:
#include <stdio.h>
int main()
{
int a, b, c;
a = 2000000000;
b = 2000000000;
c = 2100000000;
printf("%d + %d = %d\n", a, b, a+b);
if ((a + b) > c)
{
printf("%d + %d > %d\n", a, b, c);
}
else
{
printf("%d + %d < %d\n", a, b, c);
}
return 0;
}
Displays the following:
2000000000 + 2000000000 = -294967296
2000000000 + 2000000000 < 2100000000
|
There's object-based databases(Gemstore, for example). Google's Big-Table and Amason's Simple Storage I am not sure how you would categorize, but both are map-reduce based. |
In C, you use a void in an empty function reference so that compiler has a prototype, and that prototype is "no arguments". In C++, you don't have to tell the compiler that you have a prototype because you can't leave out the prototype. |
Also a little silly, but you could try picking an arbitrary day and embedding each time in it, using `datetime.datetime.combine`, then subtracting:
>>> import datetime
>>> t1 = datetime.time(2,3,4)
>>> t2 = datetime.time(18,20,59)
>>> dummydate = datetime.date(2000,1,1)
>>> datetime.datetime.combine(dummydate,t2) - datetime.datetime.combine(dummydate,t1)
datetime.timedelta(0, 58675) |
Have a look at [IDA Pro][1] - The Interactive Disassembler. It is an amazing disassembler.
If you want to debug, not just reverse engineer, try PEBrowse Professional Interactive from [SmidgeonSoft][2]
[1]: http://www.hex-rays.com/idapro/
[2]: http://www.smidgeonsoft.prohosting.com/pebrowse-pro-interactive-debugger.html |
I realize your question pertains to C++, but when it comes to C the answer can be found in K&R, pages 72-73:
<hr>
Furthermore, if a function declaration does not include arguments, as in
double atof();
that too is taken to mean that nothing is to be assumed about the arguments of atof; all parameter checking is turned off. This special meaning of the empty argument list is intended to permit older C programs to compile with new compilers. But it's a bad idea to use it with new programs. If the function takes arguments, declare them; if it takes no arguments, use void. |
To add to Jim's answer you could also use the word list and randomly replace certain characters with symbols (an @ for an A, a 0 (zero) for an O or a 5 for an S) and/or remove the vowels from the words.
- lmn%Desk
- p@per&b0y32H@t
Still mostly human readable. |
You have to wrap the word in a span to accomplish this. |
Multiple Eval Fields in Gridview ItemTemplate |
|asp.net|data-binding|gridview|eval| |
I just learned a new trick and thought I'd share it (and try to find an *even better* way).
I wanted to display two data-bound fields in a single ASP.NET Gridview ItemTemplate.
I also wanted to have some control over the formatting.
I had previously used this (bad, I know):
<%# Eval("Name1", "{0} - ")%> <%#Eval("Name2")%>
Result = 'John - Smith'
But just discovered that I can also put TWO (or more) Evals in the same data-bound group:
<%#Eval("Name1") & " - " & Eval("Name2")%>
Result = 'John - Smith'
Or
<%# "First Name - " & Eval("Name1") & ", Last Name - " & Eval("Name2")%>
Result = 'First Name - John, Last Name - Smith'
This technique gives me *much* more control over the formatting without having to resort to putting string handling in the RowDataBound event of the GridView.
But I know from experience that there is *ALWAYS* a better way to do something so....
**What techniques/tricks do _you use_ when binding and formatting data in a GridView/DataList/Repeater?**
|
Best Technique for Multiple Eval Fields in Gridview ItemTemplate? |
What is the best way to use multiple EVAL fields in a GridView ItemTemplate?
Looking to have some control over formatting for appearance as well as setting up hyperlinks/javascript etc.
|
What you are looking for is a pseudoclass that doesn't exist. There is :first-letter and :first-line, but no :first-word.
You can of course do this with JavaScript. Here's some code I found that does this: [http://www.dynamicsitesolutions.com/javascript/first-word-selector/][1]
[1]: http://www.dynamicsitesolutions.com/javascript/first-word-selector/ |
Use the [strong][1] element, that is it's purpose:
<div id="content">
<p><strong>First Word</strong> rest of paragraph.</p>
</div>
Then create a style for it in your style sheet.
#content p strong
{
font-size: 14pt;
}
[1]: http://www.w3schools.com/tags/tag_phrase_elements.asp |
There isn't a plain CSS method for this. You might have to go with JavaScript + Regex to pop in a span.
Ideally, there would be a pseudo-element for first-word, but you're out of luck as that doesn't appear to work. We do have :first-letter and :first-line.
You might be able to use a combination of :after or :before to get at it without using a span. |
I had previously used this (bad, I know):
<%# Eval("Name1", "{0} - ")%> <%#Eval("Name2")%>
Result = 'John - Smith'
But just discovered that I can also put TWO (or more) Evals in the same data-bound group:
<%#Eval("Name1") & " - " & Eval("Name2")%>
Result = 'John - Smith'
Or
<%# "First Name - " & Eval("Name1") & ", Last Name - " & Eval("Name2")%>
Result = 'First Name - John, Last Name - Smith' |
|design-patterns|oop|tutorials|delegates| |
This looks like the same question as:
http://stackoverflow.com/questions/29677/how-do-i-make-the-manifest-of-a-net-assembly-private
See my answer there:
http://stackoverflow.com/questions/29677/how-do-i-make-the-manifest-of-a-net-assembly-private#29692
"I think what you're talking about is "obfuscation". There are lots of articles about it on the net:
http://en.wikipedia.org/wiki/Obfuscation
The "standard" tool for obfuscation on .NET is by Preemptive Solutions:
http://www.preemptive.com/obfuscator.html
They have a community edition that ships with Visual Studio which you can use.
You mentioned ILDasm, have you looked at the .NET Reflector?
http://aisto.com/roeder/dotnet/
It gives you an even better idea as to what people can see if you release a manifest!" |
As the first answer says, what are your criteria? There's a number of commercial and open-source tools in the same space (but not Javaspaces-based):
* [Oracle Coherence][1]
* [Gemstone's Gemfire][2]
* [Terracotta][3] (a degree of overlap, but not quite in the same space)
* [GridGain][4] (does the grid bit, but not the distributed cache bit)
[1]: http://coherence.oracle.com/display/COH34UG/Coherence+3.4+Home
[2]: http://www.gemstone.com/products/gemfire/
[3]: http://www.terracotta.org
[4]: http://www.gridgain.com |
How to fetch HTML in Java |
|java|html| |
Without the use of any external library, what is the simplest way to fetch a website's HTML content into a String? |
|java|html|screen-scraping| |
You can use CDATA section
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
or you can describe   in local DTD:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE local [
<!ENTITY nbsp " ">
]>
or use ` ` instead of   |
You can use CDATA section
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
or you can describe   in local DTD:
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
or just use ` ` instead of ` ` |
(Why) should I use obfuscation? |
|.net|security|obfuscation|protection| |
It seems to me obfuscation is an idea that falls somewhere in the "security by obscurity" or "false sense of protection" camp. To protect intellectual property, there's copyright; to prevent security issues from being found, there's *fixing those issues*. In short, I regard it as a technical solution to a social problem. [Those almost never work.][1]
However, I seem to be the only one in our dev team to feel that way, so I'm either wrong, or just need convincing arguments. Our product uses .NET, and one dev suggested .NET Reactor (which, incidentally, [was suggested in this SO thread as well][2]).
>.NET Reactor completely stops any decompiling by mixing any pure .NET assembly (written in C#, VB.NET, Delphi.NET, J#, MSIL...) with native machine code.
So, basically, you throw all advantages of bytecode away in one go?
Are there good *engineering* benefits to obfuscation?
[1]: http://www.ietf.org/mail-archive/web/ietf/current/msg22508.html
[2]: http://stackoverflow.com/questions/2525/best-net-obfuscation-toolsstrategy#22990 |
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 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 } ); // Equivalent to calling convention 1.
**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 ); // Equivalent to calling convention 2.
<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[][]`" parameter. This would allow you to pass multiple arrays as arguments:
void Foo( params object[][] arrays ) {
foreach( object[] array in arrays ) {
// process array
}
}
...
Foo( new[] { "1", "2" }, new[] { "3", "4" } );
// Equivalent to:
object[][] arrays = new[] {
new[] { "1", "2" },
new[] { "3", "4" }
};
Foo( arrays );
|
I would recommend following the [inbox zero](http://video.google.com/videoplay?docid=973149761529535925) approach advocated by 43 folders. Joel Spolsky apparently uses it and a lot of people feel it's a great way of decluttering and organising your email life :-). |
You could use the excellent <a href="http://www.codeplex.com/umbrella">Umbrella library</a>:
using nVentive.Umbrella.Extensions.Calendar;
DateTime beginning = DateTime.Now.BeginningOfWeek();
However, they *do* seem to have stored Monday as the first day of the week (see the property `nVentive.Umbrella.Extensions.Calendar.DefaultDateTimeCalendarExtensions.WeekBeginsOn`), so that previous localized solution is a bit better. Unfortunate. |
Operations (methods) are looked-up by name, so you could probably get away with recompiling only the clients that use the new operation. |
Operations (methods) are looked-up by name, so you only need to recompile the clients that use the new operation. |
As I understand it, this is fine so long as you are linking .so files which were all compiled using the same compiler. Different compilers mangle the symbols in different ways and will fail to link.
That is one of the advantages in using COM on Windows, it defines a standard for putting OOP objects in DLLs. I can compile a DLL using GNU g++ and link it to an EXE compiled with MSVC - or even VB!
|
Use the [Xdebug][1] extension to profile PHP code.
[1]: http://www.xdebug.org/ |
It works because OnSetFocus (like many of the On* methods) gives you a chance to pre-empt an action before it actually occurs. The focus never actually switches to your non-interactive window. |
You can embed your data in the XMP tag within a JPEG (or EXIF or IPTC fields for that matter).
XMP is XML so you have a fair bit of flexibility there to do you own custom stuff.
It's probably not *the simplest thing possible* but putting your data here will maintain the integrity of the JPEG and require no "post processing".
You data will then show up in other imaging software such as PhotoShop, which may not be ideal.
|
Older non-relational databases:
[Network Database][1]
[Hierarchical Database][2]
Both mostly went out of style when relational became feasible.
[1]: http://en.wikipedia.org/wiki/Network_database
[2]: http://en.wikipedia.org/wiki/Hierarchical_database |
The simplest way I can think of is to run the rsync command from within a Windows Shell script (vbs or cmd). |
What are some good usability guidelines an average developer should follow? |
|usability|guildelines| |
I'm not a usability specialist, and I really don't care to be one.
I just want a small set of rules of thumb that I can follow while coding my User Interfaces so that my product has decent usability.
At first I thought that this question would be easy to answer "Use your common sense", but if it's so common among us developers we wouldn't, as a group, have a reputation for our horrible interfaces.
Any Suggestions? |
I've gotten more control using [urlrewriter.net](http://urlrewriter.net/) |
I've gotten more control using [urlrewriter.net](http://urlrewriter.net/), something like:
<unless header="Host" match="^www\.">
<if url="^(https?://)[^/]*(.*)$">
<redirect to="$1www.domain.tld$2"/>
</if>
<redirect url="^(.*)$" to="http://www.domain.tld$1"/>
</unless> |
Read [Don't Make Me Think by Steve Krug][1]. It is a great starting point, and an easy short read.
EDIT: This is mainly for web usability though, but it would still be a good read even if you are doing rich clients.
[1]: http://www.amazon.com/Dont-Make-Me-Think-Usability/dp/0321344758/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1220922198&sr=8-1 |
[Column-oriented databases](http://en.wikipedia.org/wiki/Column-oriented_DBMS) are also a bit of a different animal. Many of them do support standard relational database SQL though. These are generally used for data warehouse type applications. |
I'll add OCaml to the list, which has really *generic* generics. I agree that Haskell's type classes are really well done, but it's a bit different in that Haskell has no OO semantics, but OCaml does support OO. |
IDA Pro won't be much use to you if you want to find out what 'messages' are being sent. You should realise that this is a very big step up for most web developers, but you already knew that?
I would start by deciding if you really need to work at the driver-level, often this is the Kernel level. The user mode level may be where you want to look first. Use a tool like WinSpy or other Windows debug tool to find out what [messages][1] are getting passed around by your driver software, and the mouse configuration applet in control panel. You can use the Windows API function called [SendMessage()][2] to send your messages to the application from user mode.
Your first stop for device driver development should be the [Windows DDK docs][3] and [OSR Online][4].
[1]: http://msdn.microsoft.com/en-us/library/ms644927.aspx
[2]: http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx
[3]: http://www.microsoft.com/whdc/devtools/wdk/default.mspx
[4]: http://www.osronline.com/ |
Is it a large system with many programmers? If so it might be worth checking that nowhere in the code is the logger having its config changed programatically.
In log4j, this can be done using the `LogManager` or `BasicConfigurator` classes. Also via the `PropertyConfigurator` and `DomConfigurator`. Just one rogue line of code could set up a new Logger to stdout using the PatternLayout shown in your example.
BasicConfigurator.configure();
|
With PowerShell you could add the folders as variables in your profile.ps1 file, like:
$vids="C:\Users\mabster\Videos"
Then, like Unix, you can just refer to the variables in your commands:
cd $vids
Having a list of variable assignments in the one ps1 file is probably easier than maintaining separate batch files.
|
Do you need to schedule a recurring task? In that case I recommend you consider using [Quartz][1].
[1]: http://opensymphony.com/quartz/ |
SqlCommand myCommand = new SqlCommand("INSERT INTO ... VALUES ...");
myCommand.Connection = new SqlConnection("Your connection string");;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close(); |
using (SqlConnection myConnection new SqlConnection("Your connection string"))
{
SqlCommand myCommand = new SqlCommand("INSERT INTO ... VALUES ...", myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
}
|
@[Jas](#30921), it's a special feature in Visual Studio. The procedure is outlined in [this blog entry, called "Sharing a Strong Name Key File Across Projects"][1]. The example is for sharing strong name key files, but will work for any kind of file.
Briefly, you right-click on your project and select "Add Existing Item". Browse to the directory of the file(s) you want to link and highlight the file or files. Insted of just hitting "Add" or "Open" (depending on your version of Visual Studio), click on the little down arrow on the right-hand side of that button. You'll see options to "Open" or "Link File" if you're using Visual Studio 2003, or "Add" or "Add as Link" with 2005 (I'm not sure about 2008). In any case, choose the one that involves the word "Link". Then your project will essentially reference the file - it will be accessible both from the original project its was in and the project you "linked" it to.
This is a convenient way to create an assembly that contains all the functionality of wrapper.dll and api.dll, but you'll have to remember to repeat this procedure every time you add a new file to api.dll (but not wrapper.dll).
[1]: http://blogs.msdn.com/shawnfa/archive/2006/04/24/582278.aspx |
Without Powershell you can do it like this:
C:\>set DOOMED=c:\windows
C:\>cd %DOOMED%
C:\WINDOWS> |
Environment variables?
set home=D:\profiles\user\home
set svn-project1=D:\projects\project1\svn\branch\src
cd %home%
On Unix I use this along with popd/pushd/cd - all the time. |
You'll probably have to use a tool, such as [ILMerge][1], to merge the two assemblies, such as.
[1]: http://research.microsoft.com/~mbarnett/ILMerge.aspx |
Looks like a call to <code>myListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)</code> will do what you want. I would think, just call it after adding an item.
More info [here](http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.autoresizecolumns(VS.85\).aspx) |
You could create your own JSP function.
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags6.html
This is roughly what you need to do.
Create a tag library descriptor file <br/>
/src/META-INF/sf.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>sf</short-name>
<uri>http://www.stackoverflow.com</uri>
<function>
<name>clean</name>
<function-class>com.stackoverflow.web.tag.function.TagUtils</function-class>
<function-signature>
java.lang.String clean(java.lang.String)
</function-signature>
</function>
</taglib>
Create a Java class for the functions logic.<br/>
com.stackoverflow.web.tag.function.TagUtils
package com.stackoverflow.web.tag.function;
import javax.servlet.jsp.tagext.TagSupport;
public class TagUtils extends TagSupport {
public static String clean(String comment) {
return comment.replaceAll("\n", "; ");
}
}
In your JSP you can access your function in the following way.
<%@ taglib prefix="sf" uri="http://www.stackoverflow.com"%>
${fn:clean(item.comments)}
|
Fire up Process Monitor (from Sysinternals, part of Microsoft), run your process and let it die, then filter the Process Monitor results by your process name -- you will be able to see everything that it did, including exit codes. |
If you want more speed you can either consider weighted reservoir sampling where you don't have to find the total weight ahead of time (but you sample more often from the random number generator). The code might look something like
Broker selected = null;
int s = 0;
foreach(Broker broker in brokers) {
s += broker.Weight;
if (broker.Weight <= _rnd.Next(0,s)) {
selected = broker;
}
}
This requires going once through the list brokers. However if the list of brokers is fixed or doesn't change that often you can keep an array of cumulative sums, i.e. A[i] is the sum of weights of all brokers 0,..,i-1. Then A[n] is the total weight and if you pick a number between 1 and A[n-1], say x you find the broker j s.t. A[j-1] <= x < A[j]. For convenience you let A[0] = 0. You can find this broker number j in log(n) steps using binary search, I'll leave the code as an easy exercise. If your data changes frequently this might not be a good way to go since every time some weight changes you might need to update a large portion of the array. |
Does re.compile() or any given Python library call throw an exception? |
|python|regex|exception| |
I can't tell from the Python documentation whether the re.compile(x) function may throw an exception (assuming you pass in a string). I imagine there is something that could be considered an invalid regular expression. The larger question is, where do I go to find if a given Python library call may throw exception(s) and what those are? |
The ubber source for anything Rails is http://www.rubyonrails.org/ if they don't have it on the site you probably don't need it.
A quick cookbook is Ruby on Rails: Up and Running you can get it from O'Rielly or search Google for a on-line version. They walk you though the conventions of Rails and use Instant Rails which is ok.
A better Rails book "Agile Web Development with Rails" This is the soups to nuts of Rails. It walks you though downloading and setting up Rails, Gems, everything.
If you want are a Java 'guy' and want a transition book O'Reilly has "Rails for Java Developers" http://oreilly.com/catalog/9780977616695/?CMP=AFC-ak_book&ATT=Rails+for+Java+Developers |
Another difference is that function return types and parameter types did not need to be defined. They would be assumed to be ints.
f(x)
{
return x + 1;
}
and
int f(x)
int x;
{
return x + 1;
}
are identical. |
Where is the console API for WebKit/Safari? |
|javascript|console|safari| |
WebKit/Safari supports the console object, which is similar to what Firebug does. But what exactly is supported? There is a [console documentation for Firebug][1], but where can I find the console documentation for Safari/WebKit?
[1]: http://getfirebug.com/console.html |
Here are the character sets that Steve Gibson uses for his ["Perfect Paper Password"][1] system. They are "characters to allow" rather than "characters to avoid", but they seem pretty reasonable for what you want:
A standard set of 64 characters
!#%+23456789:=?@ABCDEFGHJKLMNPRS
TUVWXYZabcdefghijkmnopqrstuvwxyz
A larger set of 88 characters
!"#$%&'()*+,-./23456789:;<=>?@ABCDEFGHJKLMNO
PRSTUVWXYZ[\]^_abcdefghijkmnopqrstuvwxyz{|}~
For pronounceable passwords, I'm not familiar with the algorithms but you might want to look at [APG][2] and [pwgen][3] as a starting point.
[1]: https://www.grc.com/ppp.htm
[2]: http://www.adel.nursat.kz/apg/
[3]: http://sourceforge.net/projects/pwgen/ |
You can simulate private methods like this:
function Restaurant()
{
}
Restaurant.prototype = (function()
{
var private_stuff = function()
{
// Private code here
};
return {
constructor:Restaurant,
use_restroom:function()
{
private_stuff();
}
};
})();
var r = new Restaurant();
// This will work:
r.use_restroom();
// This will cause an error:
r.private_stuff();
More information on this technique here: <http://webreflection.blogspot.com/2008/04/natural-javascript-private-methods.html> |
JavaScript private methods |
|javascript|methods|private| |
To make a JavaScript class with a public method I'd do something like:
function Restaurant()
{
}
Restaurant.prototype.buy_food = function()
{
// something here
}
Restaurant.prototype.use_restroom = function()
{
// something here
}
That way users of my class can:
var restaurant = new Restaurant();
restaurant.buy_food();
restaurant.use_restroom();
How do I create a private method that my public buy_food and use_restroom methods can call but that users of the class can't call externally.
In other words, I want my method implementation to be able to do:
Restaurant.prototype.use_restroom = function()
{
this.private_stuff();
}
But this shouldn't work:
var r = new Restaurant();
r.private_stuff();
How do I define private_stuff as a private method so both of those hold true?
I've read [Doug Crockford's writeup][1] a few times but it doesn't seem like "private" methods can be called by public methods and "privileged" methods can be called externally.
[1]: http://javascript.crockford.com/private.html |
Being relatively new to python I'm not sure what the most common idiom is, but the simplest thing I can think of is just using a module instead of a class. What would have been instance methods on your class become just functions in the module and any data just becomes variables in the module instead of members of the class. I suspect this is the pythonic approach to solving the type of problem that people use singletons for.
If you really want a singleton class, there's a reasonable implementation described on the [first hit on google](http://www.python.org/workshops/1997-10/proceedings/savikko.html) for "python singleton", specifically:
class Singleton:
__single = None
def __init__( self ):
if Singleton.__single:
raise Singleton.__single
Singleton.__single = self
That seems to do the trick. |
Does Visual Studio Server Explorer support custom database providers? |
|c#|visual-studio|mysql|oracle-database|sqlite| |
I had used Server Explorer and related tools for graphical database development with Microsoft SQL Server in some of my learning projects - and it was a great experience. However, in my work I deal with Oracle DB and SQLite and my hobby projects use MySQL (because they are hosted on Linux).
Is there a way to leverage the database-related tools in Visual Studio with other database providers? |
one other possibility to use html entities from within xslt is the following one:
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text> |
I don't really see the need, as a module with functions (and not a class) would serve well as a singleton. All it's variables would be bound to the module, which could not be instantiated repeatedly anyways.
If you do wish to use a class, there is no way of creating private classes or private constructors in python, so you can't protect against multiple instantiations, other than just via convention in use of your API. I would still just put methods in a module, and consider the module as the singleton. |
I think you should actually have a submit button or a submit image... Do you have a specific reason for using a "submit div"? If you just want custom styles I recommend `<input type="image"...`. [http://webdesign.about.com/cs/forms/a/aaformsubmit_2.htm][1]
[1]: http://webdesign.about.com/cs/forms/a/aaformsubmit_2.htm |
Wouldn't solutions like VMware's ThinApp (Formerly Thinstall) help a bit with protecting your code also?
It comes at an extremely high price though.. |
Reflection is what you're looking for.
You could look up the type using something like this
public IYourInterface GetClass(string className)
{
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type type in asm.GetExportedTypes())
{
if (type.FullName == className)
return Activator.CreateInstance(type, constructorargs) as IYourInterface;
}
}
return null;
}
For assigning property values you also use reflection. Something along the lines of
IYourInterface o = GetClass("class1");
o.GetType().GetProperty("prop1").SetValue(o, "foo", null);
|
The [PostgreSQL manual][1] indicates that this means the transaction is open (inside BEGIN) and idle. It's most likely a user connected using the monitor who is thinking or typing. I have plenty of those on my system, too.
If you're using Slony for replication, however, the [Slony-I FAQ][2] suggests `idle in transaction` may mean that the network connection was terminated abruptly. Check out the discussion in that FAQ for more details.
[1]: http://www.postgresql.org/docs/8.3/interactive/monitoring-ps.html
[2]: http://slony1.projects.postgresql.org/slony1-1.2.6/doc/adminguide/faq.html |
The single most important piece of advice I'd give someone is to work on the UI first. Pen and paper and all. That way, you won't subconsciously couple buttons to functions, input fields to variables, etc.
The best UI might be a pain to code, and if your backend code is mostly written, it will sabotage your thinking.
Other than that, I'd point to [Apple's Human Interface Guidelines][1]. Of course, if your platform is not OSX, take the OSX sections with a lot of salt. What works in OSX might not work on Windows. You should embrace your platform's idioms.
OSX stuff aside, that document has some pretty good starting points on the fundamentals.
[1]: http://developer.apple.com/documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGIntro/chapter_1_section_1.html |
- Don't make things work in a different way than your users are expecting (i.e. breaking the "back" button when using Ajax in web forms
- Follow the K.I.S.S principal
Really, any rules someone posts will be a variation on the theme:
**Don't Make Your Users Think** |
- Don't make things work in a different way than your users are expecting (i.e. breaking the "back" button when using Ajax in web forms
- Follow the K.I.S.S principal
Really, any rules someone posts will be a variation on the theme:
**Don't Make Your Users Think**
"Don't Make Me Think" has already been posted, see also
[Design of Everyday Things][1] and [Designing with Web Standards][2] which are also great for light usability reading.
[1]: http://www.amazon.com/Design-Everyday-Things-Donald-Norman/dp/0465067107/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1220922451&sr=8-1
[2]: http://www.amazon.com/Designing-Web-Standards-Jeffrey-Zeldman/dp/0321385551/ref=sr_1_1?ie=UTF8&s=books&qid=1220922543&sr=1-1 |
When you say lock up, do you mean VS is actually hung, or do the tests not run?
The easiest way to track down what is going on would be to look at a dump of the hung process. If you are on Vista, just right-click on the process and choose to create a memory dump. If you are on Windows XP, and don't have the <a href="http://www.microsoft.com/whdc/DevTools/Debugging/default.mspx">Debugging Tools for Windows</a> installed, you can get a memory dump using ntsd.exe. You'll need the process ID, which you can get from Task Manager by adding the PID column to the Processes tab display.
Once you have that, run the following commands:
ntsd -p <PID>
.dump C:\mydump.dmp
You can then either inspect that dump using <a href="http://blogs.msdn.com/johan/archive/2007/11/13/getting-started-with-windbg-part-i.aspx">WinDBG and SOS</a> or if you can post the dump somewhere I'd be happy to take a look at it.
In any case, you'll want to likely take two dumps about a minute apart. That way if you do things like !runaway you can see which threads are working which will help you track down why it is hanging.
One other question - are you on VS2008 SP1? |
You could write your own JSTL function to do the replacement.
This means you'd end up with something like:
<%@ taglib prefix="ns" uri="..." %>
...
${ns:replace(data)}
Where ``ns`` is a namespace prefix you define and ``replace`` is your JSTL function.
These functions are pretty easy to implement (they're just a static method) although I can't seem to find a good reference for writing these at the moment. |
You could write your own JSP function to do the replacement.
This means you'd end up with something like:
<%@ taglib prefix="ns" uri="..." %>
...
${ns:replace(data)}
Where ``ns`` is a namespace prefix you define and ``replace`` is your JSP function.
These functions are pretty easy to implement (they're just a static method) although I can't seem to find a good reference for writing these at the moment. |
Finding System.Web.UI.Page from HttpContext |
|c#|asp.net| |
This is actually a two part question. First,does the HttpContext.Current correspond to the current System.UI.Page object?
And the second question, which is probably related to the first, is why can't I use the following to see if the current page implements an interface:
private IWebBase FindWebBase()
{
if (HttpContext.Current as IWebBase != null)
{
return (IWebBase)HttpContext.Current.;
}
throw new NotImplementedException("Crawling for IWebBase not implemented yet");
}
The general context is that some controls need to know whether they are executing as a SharePoint webpart, or as part of an Asp.Net framework.
I have solved the problem by requiring the control to pass a reference to itself, and checking the Page property of the control, but I'm still curious why the above does not work.
The compiler error is:
Cannot convert System.Web.HttpContext to ...IWebBase via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion or null type conversion. |
To me, [the best Java <-> JSON parser is XStream][1] (yes, I'm really talking about json, not about xml). XStream already deals with circular dependencies and has a simple and powerful api where you could write yours drivers, converters and so on.
Kind Regards
[1]: http://xstream.codehaus.org/json-tutorial.html |
Python has the [htmlentitydefs][1] module, but this doesn't include a function to unescape HTML entities.
Python developer Fredrik Lundh (author of elementtree, among other things) has [such a function][2] on his website, which works with decimal, hex and named entities.
[1]: http://docs.python.org/lib/module-htmlentitydefs.html
[2]: http://effbot.org/zone/re-sub.htm#unescape-html
|