instruction stringlengths 0 30k ⌀ |
|---|
When learning a new programming language, one of the possible roadblocks you might encounter is the question whether the language is, by default, *pass-by-value or pass-by-reference*
So here is my question to all of you, in your favorite language, *how* is it actually done? and what are the *possible pitfalls*?
your favorite language can, of course, be anything you have ever played with: popular, obscure, esoteric, new, old ... |
One interesting way is to maintain a stack, and only merge if the list on the stack has the same number of elements, and otherwise push the list, until you run out of elements in the incoming list, and then merge up the stack. |
Fair enough. You probably know more than I do about Windows Mobile. :) I just started programming for it. But in regular WinForms, you can override the OnXxx event handler methods all you want. A quick look in Reflector with the CF shows that Control, TextBoxBase and TextBox don't prevent you from overriding the OnMouseDown event handler.
Have you tried this?:
public class MyTextBox : TextBox
{
public MyTextBox()
{
}
protected override void OnMouseDown(MouseEventArgs e)
{
//do something specific here
base.OnMouseDown(e);
}
} |
Try this.
<asp:Button id="myButton" runat="server" style="display:none" Text="Click Me" />
<script type="text/javascript">
function ShowButton() {
var buttonID = '<%= myButton.ClientID %>';
var button = document.getElementById(buttonID);
if(button) { button.style.display = 'inherit'; }
}
</script>
Don't use server-side code to do this because that would require a postback. Instead of using Visibility="false", you can just set a CSS property that hides the button. Then, in javascript, switch that property back whenever you want to show the button again. |
Try this.
<asp:Button id="myButton" runat="server" style="display:none" Text="Click Me" />
<script type="text/javascript">
function ShowButton() {
var buttonID = '<%= myButton.ClientID %>';
var button = document.getElementById(buttonID);
if(button) { button.style.display = 'inherit'; }
}
</script>
Don't use server-side code to do this because that would require a postback. Instead of using Visibility="false", you can just set a CSS property that hides the button. Then, in javascript, switch that property back whenever you want to show the button again.
The ClientID is used because it can be different from the server ID if the button is inside a Namaing Container control. These include Panels of various sorts. |
IE8 overflow:auto with max-height |
|internet-explorer-8|beta| |
First of all, I know IE8 is still testing. But I'd *like* to have my site look the same even in testing version... so:
I have an element which may contain very big amounts of data, but I don't want it to ruin the page layout, so I set `max-height: 100px` and `overflow:auto`, hoping for scrollbars to appear when the content does not fit. It all works fine in Firefox and IE7, but IE8 behaves as if `overflow:hidden` was present instead of `overflow:auto`. I tried `overflow:scroll`, still does not help, IE8 simply truncates the content without showing scrollbars.
Does anyone know of a workaround? For now I resorted to using `height` instead of `max-height`, but it leaves plenty of empty space in case there isn't much data.
Before you tell me to do that, yes, I've reported the bug to IE developers :) |
|beta|internet-explorer-8| |
Please see the following for an example which shows the declaration and potential usage:
namespace Flags
{
class Program
{
[FlagsAttribute]
public enum MyFlags : short
{
Foo = 0x1,
Bar = 0x2,
Baz = 0x4
}
static void Main(string[] args)
{
MyFlags fooBar = MyFlags.Foo | MyFlags.Bar;
if ((fooBar & MyFlags.Foo) == MyFlags.Foo)
{
Console.WriteLine("Item has Foo flag set");
}
}
}
} |
The ElementName property on a Binding is not supported in Silverlight.
You will notice, if you go into the code behind or inspect the Binding object in class explorer, it doesn't have a property named ElementName. |
You can also do this
[Flags]
public enum MyEnum
{
None = 0,
First = 1,
Second = 1 << 1,
Third = 1 << 2,
Fourth = 1 << 3
}
I find the bit-shifting easier than typing 4,8,16,32 and so on. It has no impact on your code because it's all done at compile time |
If you make use of WPF commands, each custom command could then log the Action taken. You can also log the way the command was initiated. |
I haven't used MSVC6 in years, but I remember the debugger basically being a flaky piece of crap. Things like this would regularly happen for no apparent reason because it just didn't like your code that day.
In addition to the debugger being a flaky piece of crap, the rest of it was too.
It's STL implementation isn't threadsafe, it doesn't support very much of the C++ standard, and the IDE is sorely lacking in niceties.
I'm pretty sure you also just simply can't use any versions of the Platform SDK from the last 5 years because it's too old to grok them. Not a good thing.
You'd be mad to keep using it when there is [Visual C++ Express 2008](http://www.microsoft.com/express/vc/) which you can download for free. |
Someone also suggest the Raphael Javascript library, which apparently lets you draw on the client in all popular browsers:
http://dmitry.baranovskiy.com/raphael/
.. but that wouldn't exactly work with my `<noscript>` case, now would it ? :) |
What you are asking for is handled at the OS level. Once the data is in your program, it is liable to be paged out.
For accessing the memory, a motivated individual can attach a hardware debugger. |
Be sure it isn't something [google can answer][1] though. which also shows an issue with that --order of operations!
[1]: http://www.google.com/search?q=what+is+7+minus+3+times+2%3F |
The flags attribute should be used only when bitwise operations (and, or, exclusive or, not) is to be used on the enum. One example is
myProperties.AllowedColors = MyColor.Red | MyColor.Green | MyColor.Blue;
This will render the posibility to retrieve these three distinct values from your property *AllowedColors*.
For this to work the values in your enumeration **need** to be **multiples of two** (as seen in Jay Mooneys example)
[Flags]
public enum MyColor
{
Yellow = 1,
Green = 2,
Red = 4,
Blue = 8
}
To retrieve the distinct values in you property one can do this
if((myProperties.AllowedColors & MyColor.Yellow) == MyColor.Yellow)
{
// Yellow has been set...
}
if((myProperties.AllowedColors & MyColor.Green) == MyColor.Green)
{
// Green has been set...
}
**Under the covers**
This works because you previously used multiples of two in you enumeration. Under the covers your enumeration values looks like this (presented as bytes, which has 8 bits which can be 1's or 0's)
Yellow: 00000001
Green: 00000010
Red: 00000100
Blue: 00001000
Likewise, after you've set your property *AllowedColors* to Red, Green and Blue (which values where OR'ed by the pipe |), *AllowedColors* looks like this
myProperties.AllowedColors: 00001110
So when you retreive the value you are actually bitwise AND'ing the values
myProperties.AllowedColors: 00001110
MyColor.Green: 00000010
-----------------------
00000010 // Hey, this is the same as MyColor.Green!
**The None = 0 value**
And regarding use 0 in you enumeration, quoting from msdn:
[Flags]
public enum MyColor
{
None = 0,
....
}
> Use None as the name of the flag enumerated constant whose value is zero. **You cannot use the None enumerated constant in a bitwise AND operation to test for a flag because the result is always zero.** However, you can perform a logical, not a bitwise, comparison between the numeric value and the None enumerated constant to determine whether any bits in the numeric value are set.
You can find more info about the flags attribute and its usage at [msdn][1] and [designing flags at msdn][2]
[1]: http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx
[2]: http://msdn.microsoft.com/en-us/library/ms229062.aspx |
You mean it isn't already? ;)
Obviously a lot of currently-popular applications would need to offer it and make it obvious that it was a good alternative.
If Google and Facebook made it an obvious option, that would help.
Ultimately, user education will really be the thing that does it. I doubt most people would care though...dumb sheeple.
|
Try monitoring the Visual Studio process using a tool like [Process Monitor][1] and get more info. It could be because of some weird file access issues.
[1]: http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx |
I Believe the best you can do is pass a container object as an argument to a function and change the values of some properties in that object:
function swap(aValuesContainer:Object):void
{
var tempValue:int = aValuesContainer["a"];
aValuesContainer["a"] = aValuesContainer["b"];
aValuesContainer["b"] = tempValue;
}
var ints:Object = {a:13, b:25};
swap(ints); |
I Believe the best you can do is pass a container object as an argument to a function and change the values of some properties in that object:
function swapAB(aValuesContainer:Object):void
{
if (!(aValuesContainer.hasOwnProperty("a") && aValuesContainer.hasOwnProperty("b")))
throw new ArgumentError("aValuesContainer must have properties a and b");
var tempValue:int = aValuesContainer["a"];
aValuesContainer["a"] = aValuesContainer["b"];
aValuesContainer["b"] = tempValue;
}
var ints:Object = {a:13, b:25};
swapAB(ints); |
It would certainly help if more OpenID consumers were also OpenID providers. As a developer, I'm comfortable going through a few contortions to figure out that I can create a new ID on openid.org, but the more mainstream consumer could easily be put off by the process. |
Yes, you can add a bat file to svn (on the installed server) so that anytime you update a particular branch, that change get mimicked.. I believe its called hooks...
I hope this is what you meant.
|
There's a control code you can pass to [DeviceIoControl][1] to get the physical disk geometry.
[1]: http://msdn.microsoft.com/en-us/library/aa365171(VS.85).aspx |
I finally got this working with danb's help above.
This is my resource bundle class and resource bundle control class.
I used this code from danb.
ResourceBundle bundle = ResourceBundle.getBundle("AwesomeBundle", locale, DbResourceBundle.getMyControl());
javax.servlet.jsp.jstl.core.Config.set(actionBeanContext.getRequest(), Config.FMT_LOCALIZATION_CONTEXT, new LocalizationContext(bundle, locale));
and wrote this class.
public class DbResourceBundle extends ResourceBundle
{
private Properties properties;
public DbResourceBundle(Properties inProperties)
{
properties = inProperties;
}
@Override
@SuppressWarnings(value = { "unchecked" })
public Enumeration<String> getKeys()
{
return properties != null ? ((Enumeration<String>) properties.propertyNames()) : null;
}
@Override
protected Object handleGetObject(String key)
{
return properties.getProperty(key);
}
public static ResourceBundle.Control getMyControl()
{
return new ResourceBundle.Control()
{
@Override
public List<String> getFormats(String baseName)
{
if (baseName == null)
{
throw new NullPointerException();
}
return Arrays.asList("db");
}
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException,
InstantiationException, IOException
{
if ((baseName == null) || (locale == null) || (format == null) || (loader == null))
throw new NullPointerException();
ResourceBundle bundle = null;
if (format.equals("db"))
{
Properties p = new Properties();
DataSource ds = (DataSource) ContextFactory.getApplicationContext().getBean("clinicalDataSource");
Connection con = null;
Statement s = null;
ResultSet rs = null;
try
{
con = ds.getConnection();
StringBuilder query = new StringBuilder();
query.append("select label, value from i18n where bundle='" + StringEscapeUtils.escapeSql(baseName) + "' ");
if (locale != null)
{
if (StringUtils.isNotBlank(locale.getCountry()))
{
query.append("and country='" + escapeSql(locale.getCountry()) + "' ");
}
if (StringUtils.isNotBlank(locale.getLanguage()))
{
query.append("and language='" + escapeSql(locale.getLanguage()) + "' ");
}
if (StringUtils.isNotBlank(locale.getVariant()))
{
query.append("and variant='" + escapeSql(locale.getVariant()) + "' ");
}
}
s = con.createStatement();
rs = s.executeQuery(query.toString());
while (rs.next())
{
p.setProperty(rs.getString(1), rs.getString(2));
}
}
catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException("Can not build properties: " + e);
}
finally
{
DbUtils.closeQuietly(con, s, rs);
}
bundle = new DbResourceBundle(p);
}
return bundle;
}
@Override
public long getTimeToLive(String baseName, Locale locale)
{
return 1000 * 60 * 30;
}
@Override
public boolean needsReload(String baseName, Locale locale, String format, ClassLoader loader, ResourceBundle bundle, long loadTime)
{
return true;
}
};
} |
This functionality isn't part of the default PostgreSQL install, but you can add it in. It's called [dblink][1].
I've never used it, but it is maintained and distributed with the rest of PostgreSQL. If you're using the version of PostgreSQL that came with your Linux distro, you might need to install a package called postgresql-contrib.
[1]: http://www.postgresql.org/docs/8.3/static/dblink.html |
I agree most important is not what style one uses but it being consistent.
With that said, the new MS/.NET styling for private fields tends to be _fooVar (underscore followed by a camelCased name) |
In the options, you can specify how much you want to grow by. By default i believe it's 10%, so given a 200MB database, when you fill your last page, it will allocate another 20MB of page space. At 7GB it would allocate 700MB.
I don't know exactly where you can modify it after you create a db, but i know it has it when you create the db. a little google work will most likely reveal the answer to you.
NOTE: my answer is not how to fix it, but maybe how to prevent / explain why you might see all this unallocated space. |
WebBrowserControl Scroll to Bottom |
|.net|user-controls|wysiwyg| |
I am working on a simple chat application using a System.Windows.Forms.WebBrowser Control to display the messages between the user and the recipient. How do I get the control to automatically scroll to the bottom every time I update the DocumentText of the control?
|
At least one resource points to this as an alternative to XmlNodeWriter: [http://msdn.microsoft.com/en-us/library/5x8bxy86.aspx][1]. Otherwise, you could write MS using that form they have on the new MSDN Code Library replacement for GotDotNet looking for XmlNodeWriter.
[1]: http://msdn.microsoft.com/en-us/library/5x8bxy86.aspx |
I have found that if you do not take care to backup your transistion log file (the LDF) you will get something like this behavior. I can not stress enough the importance of having good backup "hygiene". Not only will it save your bacon if something goes wrong but I will also help maintain a nice tight database. |
I would use the AutoScrollOffset property and set it the the bottom left of the WebBrowser control, so something like:
webCtrl.AutoScrollOffset = new Point(webCtrl.Height, 0); |
Thanks to all of you that helped to point me in the right direction. I made a change to only clear/add the menu when the form is loaded, so I shouldn't see this error again when the form is painting. |
Doesn't **ShowDialog()** have different window behavior than just **Show()**?
What if you tried:
msgFrm.Show();
msgFrm.BringToFront();
msgFrm.Focus(); |
> I don't do many physical deletes
what about updates of the table, what is the fragmentation level. run DBCC SHOWCONTIG, then rebuild the index if it is highly fragmented. After that do a BACKUP LOG <name> WITH TRUNCATE_ONLY followed by a SHRINK command |
First of all, I know IE8 is still testing. But I'd *like* to have my site look the same even in testing version... so:
I have an element which may contain very big amounts of data, but I don't want it to ruin the page layout, so I set `max-height: 100px` and `overflow:auto`, hoping for scrollbars to appear when the content does not fit. It all works fine in Firefox and IE7, but IE8 behaves as if `overflow:hidden` was present instead of `overflow:auto`. I tried `overflow:scroll`, still does not help, IE8 simply truncates the content without showing scrollbars. Changing `max-height` declaration to `height` makes overflow work OK, it's the combination of `max-height` and `overflow:auto` that breaks things.
Does anyone know of a workaround? For now I resorted to using `height` instead of `max-height`, but it leaves plenty of empty space in case there isn't much data.
Before you tell me to do that, yes, I've reported the bug to IE developers :) |
I was just testing you guys. Here's the answer:
object cell = myDataGrid[row, col];
Actually a colleague provided the answer.
Thanks,
Mike |
I was just testing you guys. Here's the answer:
object cell = myDataGrid[row, col];
Actually a colleague provided the answer.
Thanks,
Mike |
I find that [Patrick Steele](http://weblogs.asp.net/psteele/default.aspx) answered this question best on his blog: [Avoiding IsNothing()](http://weblogs.asp.net/psteele/archive/2005/06/03/410336.aspx)
I did not copy any of his answer here, to ensure Patrick Steele get's credit for his post. But I do think if you're trying to decide whether to use Is Nothing or IsNothing you should read his post. I think you'll agree that Is Nothing is the best choice. |
Continuing with what **Dave Ward** said:
- You can't set the *Visible* property to false because the control will not be rendered.
- You should use the *Style* property to set it's *display* to *none*.
---
**Page/Control design**
<asp:Label runat="server" ID="Label1" Style="display: none;" />
<asp:Button runat="server" ID="Button1" />
---
**Code behind**
Somewhere in the load section:
Label label1 = (Label)FindControl("Label1");
((Label)FindControl("Button1")).OnClientClick = "ToggleVisibility('" + label1.ClientID + "')";
---
**Javascript file**
function ToggleVisibility(elementID)
{
var element = document.getElementByID(elementID);
if (element.style.display = 'none')
{
element.style.display = 'inherit';
}
else
{
element.style.display = 'none';
}
}
---
Of course, if you don't want to toggle but just to show the button/label then adjust the javascript method accordingly.
The important point here is that you need to send the information about the `ClientID` of the control that you want to manipulate on the client side to the javascript file either setting global variables or through a function parameter as in my example. |
LinqBridge looks like a pretty nice place to start since I have VS2008, I just need to compile and deploy to a .net 2.0 server.
I've looked at SubSonic and it's also an interesting alternative, but linqbridge seems to provide a much closer fit so I'm not going to have to go and learn a new ORM / query syntax. |
|language-agnostic|oo|byvalue|byreference|parameters|article| |
When learning a new programming language, one of the possible roadblocks you might encounter is the question whether the language is, by default, *pass-by-value or pass-by-reference*
So here is my question to all of you, in your favorite language, *how* is it actually done? and what are the *possible pitfalls*?
your favorite language can, of course, be anything you have ever played with: [popular][1], [obscure][2], [esoteric][3], [new][4], [old][5] ...
[1]: http://www.ruby-lang.org/en/
[2]: http://www.devtopics.com/a-obscure-programming-language-of-the-month/
[3]: http://en.wikipedia.org/wiki/Brainfuck
[4]: http://www.nvidia.com/object/cuda_get.html
[5]: http://en.wikipedia.org/wiki/FORTRAN |
|language-agnostic|object-oriented|parameters|pass-by-reference|pass-by-value| |
|language-agnostic|oop|parameters|pass-by-reference|pass-by-value| |
How would you access Object properties from within an object method? |
|oo|java|php|theory| |
What is the "purist" or "correct" way to access an object's properties from within an object method that is not a getter/setter method?
I know that from outside of the object you should use a getter/setter, but from within would you just do:
Java:
String property = this.property;
PHP:
$property = $this->property;
or would you do:
Java:
String property = this.getProperty();
PHP:
$property = $this->getProperty();
Forgive me if my Java is a little off, it's been a year since I programmed in Java... |
What is the "purist" or "correct" way to access an object's properties from within an object method that is not a getter/setter method?
I know that from outside of the object you should use a getter/setter, but from within would you just do:
Java:
String property = this.property;
PHP:
$property = $this->property;
or would you do:
Java:
String property = this.getProperty();
PHP:
$property = $this->getProperty();
Forgive me if my Java is a little off, it's been a year since I programmed in Java...
**EDIT:**
It seems people are assuming I am talking about private or protected variables/properties only. When I learned OO I was taught to use getters/setters for every single property even if it was public (and actually I was told never to make any variable/property public). So, I may be starting off from a false assumption from the get go. It appears that people answering this question are maybe saying that you should have public properties and that those don't need getters and setters, which goes against what I was taught, and what I was talking about, although maybe that needs to be discussed as well. That's probably a good topic for a different question though... |
|java|php|object-oriented|theory| |
|java|php|oop|theory| |
Anders gives a good summary, and here's an example of a JUnit annotation
@Test(expected=IOException.class)
public void flatfileMissing()
throws IOException
{
readFlatFile("testfiles"+separator+"flatfile_doesnotexist.dat");
}
Here the @Test annotation is telling JUnit that the flatfileMissing method is a test that should be executed and that the expected result is a thrown IOException. Thus, when you run your tests, this method will be called and the test will pass or fail based on whether an IOException is thrown. |
It would be equal to b.
The comma operator has a lower precedence than assignment. |
Be especially careful with strings. Strings often have escape sequences which you also have to respect while you're finding the end of them.
So e.g. `"This is \"a test\""`. You cannot blindly look for a double-quote to terminate. Also beware of ``"This is \\"`, which shows that you cannot just say "unless double-quote is preceded by a backslash."
In summary, make some brutal unit tests! |
Also see the most recent F# release - it has static measurement domain/dimension analysis. |
It depends entirely on how the site works. I'm in agreement with most that a sitemap is usually the best way to do it. However, if you're using a CMS, then you might need to keep it in the database. If you have a taxonomy-centric site, then use the taxonomy to build the menu. There's no "best way" to do navigation, only the best way for a given situation. |
b's value will be assigned to a.
Nothing will happen to c |
One upside I can think of is being able to specify GET parameters in the direct URL to the SWF, which will then be available in the Flash app (via `Application.application.parameters` in Flex, not sure how you'd access them in Flash CS3). This can of course be achieved by other means as well if you have an HTML wrapper but this way it's less work. |
Why do you want to use the ASP.NET AJAX Toolkit with PHP / Python?
Have you considered other non ASP.NET specific AJAX libraries like jQuery, Dojo, MooTools, YUI?
ASP.NET AJAX and the ASP.NET AJAX Toolkit is ASP.NET centric, you'll gain more flexibility using other AJAX libraries with PHP / Python. |
You can use `System.Threading.Thread.CurrentPrincipal`. |
Note that if the user pushes a button, focus on the textbox will be lost and there will be no caret position! |
loop over all you input fields...
finding the one that has focus..
then once you have your text area...
you should be able to do something like...
myTextArea.value = 'text to insert in the text area goes here';
|
I'm not sure if you can capture the caret position, but if you can, you can avoid Jason Cohen's concern by capturing the location (in relation to the string) using the text box's `onblur` event. |
We've got a similar feature.
The application menu is loaded on the master page from the database, because visible menu options depend on the user's permissions.
A couple of conventions and clever structure on the database ensure that the menu loading code is generic and automagically navigates to the proper screen upon selection of a certain menu option. We use UIP to navigate and ComponentArt for web controls.
BTW ComponentArt sucks. Then again I suppose all third party control libraries do. |
Take care to notice that the comma operator may be overloaded in C++. The actual behaviour may thus be very different from the one expected.
As an example, [Boost.Spirit](http://spirit.sourceforge.net/) uses the comma operator quite cleverly to implement list initializers for symbol tables. Thus, it makes the following syntax possible and meaningful:
keywords = "and", "or", "not", "xor";
|
If I'm not mistaken, GetHashCode is consistent given the same value, but it is NOT guaranteed to be consistent across different versions of the framework.
From the MSDN docs on String.GetHashCode():
> The behavior of GetHashCode is dependent on its implementation, which might change from one version of the common language runtime to another. A reason why this might happen is to improve the performance of GetHashCode.
|
Your question is a little large, the answer vary a lot
- If you are using Just In Time compilation (JIT) or not
- When you are using,, if your process is executed for a long time or not
All recent JVM use JIT, but on old JVM the java code is several time slower that native code.
If you have a server that run for a long period of time or batch that execute the same code again and again, the difference and up being very low.
We wrote the same batch both in C++ and in Java and run it with different dataset, the result differ for about 3 second, with dataset taking from 5 minutes to several hours.
But be careful, they are special case that there will be an important difference, for example the batch that need a lot memory. |
You could try to argue your point with a timed example, run a sql select against an indexed table and then run a loop to find exactly the same item in the same set but this time in code. The code will be much slower.
Let the database do what it was designed to do, select sets and subsets of data :) I think realistically though, all you can do is get your team together to build a set of standards which you will all code to, democracy rules! |
You can use the sp_depends stored procedure to do this:
`USE AdventureWorks
GO
EXEC sp_depends @objname = N'Sales.Customer' ;`
[http://msdn.microsoft.com/en-us/library/ms189487(SQL.90).aspx][1]
[1]: http://msdn.microsoft.com/en-us/library/ms189487(SQL.90).aspx |
Google will use meta tags, but the description, to better summarize your site. They won't help to increase your page rank.
See:
[http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=79812][1]
[1]: http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=79812 |
Another option is to use an object with public static properties. I used to use $GLOBALS but most editors don't auto complete $GLOBALS. Also, un-instantiated classes are available everywhere (because you can instatiate everywhere without telling PHP you are going to use the class). Example:
<?php
class SITE {
public static $el;
}
SITE::$el = "\n<br />\n";
function Test() {
echo SITE::$el;
}
Test();
?>
This will output `<br />`
This is also easier to deal with than costants as you can put any type of value within the property (array, string, int, etc) whereas constants cannot contain arrays.
This was suggested to my by a user on the [PhpEd forums][1].
[1]: http://forum.nusphere.com |
To confirm if you're using the provided PDB, CorporateComponent.pdb, during debugging within the Visual Studio IDE review the output window and locate the line indicating that the CorporateComponent.dll is loaded and followed by the string <code>Symbols loaded</code>.
To illustrate from a project of mine:
The thread 0x6a0 has exited with code 0 (0x0).
The thread 0x1f78 has exited with code 0 (0x0).
'AvayaConfigurationService.vshost.exe' (Managed): Loaded 'C:\Development\Src\trunk\ntity\AvayaConfigurationService\AvayaConfigurationService\bin\Debug \AvayaConfigurationService.exe', Symbols loaded.
'AvayaConfigurationService.vshost.exe' (Managed): Loaded 'C:\Development\Src\trunk\ntity\AvayaConfigurationService\AvayaConfigurationService\bin\Debug\IPOConfigService.dll', No symbols loaded.
> <code>Loaded 'C:\Development\src\...\bin\Debug\AvayaConfigurationService.exe', Symbols loaded.</code>
This indicates that the PDB was found and loaded by the IDE debugger.
As indicated by others When examining stack frames within your application you should be able to see the symbols from the CorporateComponent.pdb. If you don't then perhaps the third-party did not include symbol information in the release PDB build. |
I finally got this working with danb's help above.
This is my resource bundle class and resource bundle control class.
I used this code from @[danb]'s.
ResourceBundle bundle = ResourceBundle.getBundle("AwesomeBundle", locale, DbResourceBundle.getMyControl());
javax.servlet.jsp.jstl.core.Config.set(actionBeanContext.getRequest(), Config.FMT_LOCALIZATION_CONTEXT, new LocalizationContext(bundle, locale));
and wrote this class.
public class DbResourceBundle extends ResourceBundle
{
private Properties properties;
public DbResourceBundle(Properties inProperties)
{
properties = inProperties;
}
@Override
@SuppressWarnings(value = { "unchecked" })
public Enumeration<String> getKeys()
{
return properties != null ? ((Enumeration<String>) properties.propertyNames()) : null;
}
@Override
protected Object handleGetObject(String key)
{
return properties.getProperty(key);
}
public static ResourceBundle.Control getMyControl()
{
return new ResourceBundle.Control()
{
@Override
public List<String> getFormats(String baseName)
{
if (baseName == null)
{
throw new NullPointerException();
}
return Arrays.asList("db");
}
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException,
InstantiationException, IOException
{
if ((baseName == null) || (locale == null) || (format == null) || (loader == null))
throw new NullPointerException();
ResourceBundle bundle = null;
if (format.equals("db"))
{
Properties p = new Properties();
DataSource ds = (DataSource) ContextFactory.getApplicationContext().getBean("clinicalDataSource");
Connection con = null;
Statement s = null;
ResultSet rs = null;
try
{
con = ds.getConnection();
StringBuilder query = new StringBuilder();
query.append("select label, value from i18n where bundle='" + StringEscapeUtils.escapeSql(baseName) + "' ");
if (locale != null)
{
if (StringUtils.isNotBlank(locale.getCountry()))
{
query.append("and country='" + escapeSql(locale.getCountry()) + "' ");
}
if (StringUtils.isNotBlank(locale.getLanguage()))
{
query.append("and language='" + escapeSql(locale.getLanguage()) + "' ");
}
if (StringUtils.isNotBlank(locale.getVariant()))
{
query.append("and variant='" + escapeSql(locale.getVariant()) + "' ");
}
}
s = con.createStatement();
rs = s.executeQuery(query.toString());
while (rs.next())
{
p.setProperty(rs.getString(1), rs.getString(2));
}
}
catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException("Can not build properties: " + e);
}
finally
{
DbUtils.closeQuietly(con, s, rs);
}
bundle = new DbResourceBundle(p);
}
return bundle;
}
@Override
public long getTimeToLive(String baseName, Locale locale)
{
return 1000 * 60 * 30;
}
@Override
public boolean needsReload(String baseName, Locale locale, String format, ClassLoader loader, ResourceBundle bundle, long loadTime)
{
return true;
}
};
} |
The Perl documentation comes with a nice collection of FAQs. Your question is frequently asked:
% perldoc -q duplicate
The answer, copy and pasted from the output of the command above, appears below:
<pre>Found in /usr/local/lib/perl5/5.10.0/pods/perlfaq4.pod
How can I remove duplicate elements from a list or array?
(contributed by brian d foy)
Use a hash. When you think the words "unique" or "duplicated", think
"hash keys".
If you don't care about the order of the elements, you could just
create the hash then extract the keys. It's not important how you
create that hash: just that you use "keys" to get the unique elements.
my %hash = map { $_, 1 } @array;
# or a hash slice: @hash{ @array } = ();
# or a foreach: $hash{$_} = 1 foreach ( @array );
my @unique = keys %hash;
If you want to use a module, try the "uniq" function from
"List::MoreUtils". In list context it returns the unique elements,
preserving their order in the list. In scalar context, it returns the
number of unique elements.
use List::MoreUtils qw(uniq);
my @unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 1,2,3,4,5,6,7
my $unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 7
You can also go through each element and skip the ones you've seen
before. Use a hash to keep track. The first time the loop sees an
element, that element has no key in %Seen. The "next" statement creates
the key and immediately uses its value, which is "undef", so the loop
continues to the "push" and increments the value for that key. The next
time the loop sees that same element, its key exists in the hash and
the value for that key is true (since it's not 0 or "undef"), so the
next skips that iteration and the loop goes to the next element.
my @unique = ();
my %seen = ();
foreach my $elem ( @array )
{
next if $seen{ $elem }++;
push @unique, $elem;
}
You can write this more briefly using a grep, which does the same
thing.
my %seen = ();
my @unique = grep { ! $seen{ $_ }++ } @array;
</pre> |
The Perl documentation comes with a nice collection of FAQs. Your question is frequently asked:
% perldoc -q duplicate
The answer, copy and pasted from the output of the command above, appears below:
<pre>Found in /usr/local/lib/perl5/5.10.0/pods/perlfaq4.pod
How can I remove duplicate elements from a list or array?
(contributed by brian d foy)
Use a hash. When you think the words "unique" or "duplicated", think
"hash keys".
If you don't care about the order of the elements, you could just
create the hash then extract the keys. It's not important how you
create that hash: just that you use "keys" to get the unique elements.
my %hash = map { $_, 1 } @array;
# or a hash slice: @hash{ @array } = ();
# or a foreach: $hash{$_} = 1 foreach ( @array );
my @unique = keys %hash;
If you want to use a module, try the "uniq" function from
"List::MoreUtils". In list context it returns the unique elements,
preserving their order in the list. In scalar context, it returns the
number of unique elements.
use List::MoreUtils qw(uniq);
my @unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 1,2,3,4,5,6,7
my $unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 7
You can also go through each element and skip the ones you've seen
before. Use a hash to keep track. The first time the loop sees an
element, that element has no key in %Seen. The "next" statement creates
the key and immediately uses its value, which is "undef", so the loop
continues to the "push" and increments the value for that key. The next
time the loop sees that same element, its key exists in the hash and
the value for that key is true (since it's not 0 or "undef"), so the
next skips that iteration and the loop goes to the next element.
my @unique = ();
my %seen = ();
foreach my $elem ( @array )
{
next if $seen{ $elem }++;
push @unique, $elem;
}
You can write this more briefly using a grep, which does the same
thing.
my %seen = ();
my @unique = grep { ! $seen{ $_ }++ } @array;
</pre> |
Delete Amazon S3 buckets? |
|amazon-s3|buckets| |
I've been interacting with Amazon S3 through [S3Fox][1] and I can't seem to delete my buckets. I select a bucket, hit delete, confirm the delete in a popup, and... nothing happens. Is there another tool that I should use?
[1]: https://addons.mozilla.org/en-US/firefox/addon/3247 |
|amazon|amazon-s3|buckets| |
My first suggestion would be to use a drop-in logging tool like log4net, which will make formatting much more automatic.
If you are going to go the route of two files (and I agree with Craig that a database is probably a better choice,) you can probably save yourself a lot of heartache by having one file that is as sparse as you can make it for later fast searches and one that holds all the information in one place (metadata and data) rather than creating a metadata-only format. |
Have you installed Visual Studio 2005 Service Pack 1? |
Its true the hardware load balancer could be set to sticky sessions to solve the issue, but in a perfect world, I would like the feature turned off. |
The fact that big sites will accept OpenID isn't, on it's own, enough to make it mainstream. The closest I've seen so far was having LiveJournal both accept and provide OpenID authentication (which I believe it has been doing for quite some time).
But I think that just accepting OpenID isn't enough. What we really need is more sites like this one that refuse to make their own authentication system, and *require* OpenID authentication. If the "next big thing" said you have to use your OpenID to log in (with a really simple wizard to set up a new ID with someone else), I believe that it will start the ball properly rolling. |
What version of TinyMCE will work in Drupal 5 with google chrome? |
|drupal|tinymce| |
My drupal site (internal) will not display the TinyMCE editor when using Google Chrome browser. Has anyone gotten TinyMCE to work with Chrome in Drupal 5? |
This was the answer I gave on a [related question][1]:
/// <summary>
/// Blocks until the file is not locked any more.
/// </summary>
/// <param name="fullPath"></param>
bool WaitForFile(string fullPath)
{
int numTries = 0;
while (true)
{
++numTries;
try
{
// Attempt to open the file exclusively.
using (FileStream fs = new FileStream(fullPath,
FileMode.Open, FileAccess.ReadWrite,
FileShare.None, 100))
{
fs.ReadByte();
// If we got this far the file is ready
break;
}
}
catch (Exception ex)
{
Log.LogWarning(
"WaitForFile {0} failed to get an exclusive lock: {1}",
fullPath, ex.ToString());
if (numTries > 10)
{
Log.LogWarning(
"WaitForFile {0} giving up after 10 tries",
fullPath);
return false;
}
// Wait for the lock to be released
System.Threading.Thread.Sleep(500);
}
}
Log.LogTrace("WaitForFile {0} returning true after {1} tries",
fullPath, numTries);
return true;
}
[1]: http://stackoverflow.com/questions/41290/file-access-strategy-in-a-multi-threaded-environment-web-app#41559 |
Multi-Paradigm Languages |
|php|object-oriented|paradigms|procedural| |
In a language such as (since I'm working in it now) PHP, which supports procedural and object-oriented paradigms, is there a good rule of thumb for determining which paradigm best suits a new project? If not, how can you make the decision? |
|php|oop|paradigms|procedural| |
Use [CreateFile][1] in a loop with OPEN_ EXISTING flag and FILE_ ALL_ ACCESS (or you might need only a subset, see http://msdn.microsoft.com/en-us/library/aa364399(VS.85).aspx
Examine the handle returned against -1 (INVALID_ HANDLE_ VALUE) for failure. It's still polling, but this will save the cost of an exception throw.
EDIT: this editor/markup can't handle underscores! bah!
[1]: http://msdn.microsoft.com/en-us/library/aa363858.aspx |
In a sufficiently complex system there are some places where some UML is considered useful. The useful diagrams for a system, vary by applicability, but the most widely used ones are State Diagrams, Activity Diagrams and Sequence Diagram.
There are many enterprises who swear by them and many who outright reject them as an utter waste of time and effort.
Its best not to go overboard and think whats best for the project you are on and pick the stuff that is applicable and makes sense. |
In a sufficiently complex system there are some places where some UML is considered useful.
The useful diagrams for a system, vary by applicability. But the most widely used ones are State Diagrams, Activity Diagrams and Sequence Diagram.
There are many enterprises who swear by them and many who outright reject them as an utter waste of time and effort.
Its best not to go overboard and think whats best for the project you are on and pick the stuff that is applicable and makes sense. |
HTML differences between browsers |
|html|browsers| |
Do you know of any differences in handling HTML tags/properties in different browsers? For example, I once saw a page with a input tag with a maxlength field set to "2o". Firefox and Opera ignore the "o", and set the max length to 2, while Internet Explorer ignores the field altogether. Do you know of any more?
(Note: seeing as this will probably be a list, it would be great if the general name of the difference was in bold text, like: **Different erratic value handling in tag properties**) |