instruction stringlengths 0 30k ⌀ |
|---|
here is what a I'm doing:
object ReturnMatch(System.Type type)
{
foreach(object obj in myObjects)
{
if (obj == type)
{
return obj;
}
}
}
However, if obj is a subclass of `type`, it will not match... |
See http://www.rayninfo.co.uk/vimtips.html for a great collection of Vim tips, from the basic can't-live-without to very sophisticated stuff that you might never have thought of trying. |
I think any of the above would require a comment to explain what you're doing, thus becoming two lines. I find it simpler to do:
$element = functionThatReturnsArray();
$element = $element[0];
This way, you're not using an extra variable and it's obvious what you're doing.
|
No, you should not add them to source control since - as you said - they're user specific.
> SUO (Solution User Options): Records
> all of the options that you might
> associate with your solution so that
> each time you open it, it includes
> customizations that you
> have made.
The .user file contains the... |
If you want, you can translate this VB.Net code to C#. The theory here is that you change the size of a tab in the control.
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal handle As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As Integer) As Inte... |
If you want, you can translate this VB.Net code to C#. The theory here is that you change the size of a tab in the control.
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal handle As IntPtr, ByVal wMsg As Integer, _
ByVal wParam As Integer, ByRef lParam As I... |
If you want, you can translate this VB.Net code to C#. The theory here is that you change the size of a tab in the control.
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal handle As IntPtr, ByVal wMsg As Integer, _
ByVal wParam As Integer, ByRef lParam As I... |
Once you have data into Date objects in VB, you don't have to worry about globalization until you compare something to it or try to export it.
This is fine:
Dim FirstDate as Date = Date.UtcNow() 'or this: = NewDate (2008,09,10)'
Dim SecondDate as Date
SecondDate = FirstDate.AddDays(1)
This ... |
How do you create a process-wide singleton object? |
|.net| |
I read that the unit of granularity for static fields in .Net are per AppDomain, not per process. Is it possible to create a process-wide singleton object? |
|.net|singleton| |
Given that you have an incomplete app I would say that reworking it into an Object based app will probably be helpful.
One thing to consider is the expected size of the end application. Below a certain complexity Object based may be overkill except for the learning experience.
I started out avoiding Objects like... |
You must use marshalled calls to communicate information across AppDomains. So you need to create the state object in your parent AppDomain and then pass it to any children that want to use it. If you didn't have to do this, you'd be sharing memory across AppDomains, which defeats the purpose.
Within each AppDom... |
I think "safe for scripting" means "safe to be run from a webpage we just retrieved from some Nigerian prince". The command object should be safe to run on the server.
At work though, back in the day my colleagues didn't trust it so we had an in-house framework that basically did the same thing.
|
What are the performance characteristics of 'is' reflection in C#? |
|c#|reflection| |
It's [shown][1] that 'as' casing is much faster than prefix casting, but what about 'is' reflection? How bad is it? As you can imagine, searching for 'is' on Google isn't terribly effective.
[1]: http://www.codeproject.com/KB/cs/csharpcasts.aspx |
The original syntax was to reuse '<%= %>'
So
<wf:my-tag obj="<%= myObject %>" />
See [this part of the Sun Tag Library Tutorial][1] for an example
[1]: http://java.sun.com/products/jsp/tutorial/TagLibraries16.html#62510 |
This one is super hidden, and only occasionally useful ;-)
You can use the prototype chain to create an object that delegates to another object without changing the original object.
var o1 = { foo: 1, bar: 'abc' };
function f() {}
f.prototype = o1;
o2 = new f();
assert( o2.foo === 1 );
... |
The javascript options are all over complicating things. Do as Jon Galloway or daniels0xff suggested. |
FoxPro 2.0 files were exactly the same as dBase III files with an extra bit for any field that was of type "memo" (not sure the exact name, it's been a while). That means that if you just use a [FoxPro 2.x method][1] for accessing the files, it should work.
[1]: http://www.connectionstrings.com/?carrier=visualfo... |
Using Spry inside Java Server Faces framework |
|java|jsf|dreamweaver| |
I'm trying to insert a spry accordian into an already existing jsf page using Dreamweaver, does anyone know if this is possible? I've already tried several things, and only the labels show up. |
there are a lot of "undefined behavior". You can learn how to avoid them reading good books and reading the standards. |
The margin property is used by whatever layout engine your control host (Panel, for example) is using, in whatever way that layout engine sees fit. However, it is best used for spacing just as you assume. Just read the documentation for that specific layout engine.
It can be very handy when using a FlowLayoutPan... |
> _Are there any modern, practical
> languages that actually learn from
> Lisp instead of half-assedly copying
> "first class functions", or is there
> an inherent conflict that makes this
> impossible?_
Why aren't lisp, haskell, ocaml, or f# modern?
You might just need to take it on yourself and look at the... |
> _Are there any modern, practical
> languages that actually learn from
> Lisp instead of half-assedly copying
> "first class functions", or is there
> an inherent conflict that makes this
> impossible?_
Why aren't lisp, haskell, ocaml, or f# modern?
You might just need to take it on yourself and look at the... |
If you are using the built in membership system you can do cross sub-domain authentication with forms auth by using some like this in each web.config.
<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="~/Login.aspx" path="/"
protection="All"
... |
This creates a random number generator (SecureRandom). It then creates a byte array (byte[] bytes), length 20 bytes, and populates it with random data.
This is then encoded using BASE64 and returned.
So, in a nutshell,
1. Generate 20 random bytes
2. Encode using Base 64 |
I believe tail recursion in java is not currently optimized. The details are sprinkled throughout [this][1] discussion on LtU and the associated links. It _may_ be a feature in the upcoming version 7, but apparently it presents certain difficulties when combined with Stack Inspection since certain frames would be mis... |
If you're just worried about the article content being translated, and do not need a fully integrated option, I have used [google translation][1] in the past and it works great on a smaller scale.
[1]: http://www.google.com/language_tools |
Not using the is operator, but the Type.IsInstanceOfType Method appears to be what you're looking for.
http://msdn.microsoft.com/en-us/library/system.type.isinstanceoftype.aspx |
Use calObject.getActualMaximum(calobject.DAY_OF_MONTH)
See [Real's Java How-to][1] for more info on this.
[1]: http://www.rgagnon.com/javadetails/java-0098.html
|
Here's my suggestion:
[Flags]
public enum ThreadAccess : int
{
TERMINATE = (0x0001),
SUSPEND_RESUME = (0x0002),
GET_CONTEXT = (0x0008),
SET_CONTEXT = (0x0010),
SET_INFORMATION = (0x0020),
QUERY_INFORMATION = (0x0040),
... |
Here's a great article that explains how to configure BDC connections to web services using the BDC Definition Editor:
**Creating a Web Service Connection by Using the Business Data Catalog Definition Editor**
[http://msdn.microsoft.com/en-us/library/bb737887.aspx][1]
[1]: http://msdn.microsoft.com/en-us/lib... |
You could factor the duplicated code into a CodeableEnumHelper class:
public class CodeableEnumHelper {
public static CodeableEnum getByCode(String code, CodeableEnum[] values) {
for (CodeableEnum e : values) {
if (e.getCode().equalsIgnoreCase(code)) {
... |
Any good dictioanry API available |
|web-services| |
Lot of googling did not help me! Are there any good dictionary web based available?
I am looking for a site which can send me the meaning of words if we pass the word through query string! |
Dictionary webservice recommendation |
**For TCP client side:**
Use gethostbyname to lookup dns name to IP, it will return a hostent structure. Let's call this returned value host.
hostent *host = gethostbyname(HOSTNAME_CSTR);
Fill the socket address structure:
sockaddr_in sock;
sock.sin_family = AF_INET;
sock.sin_port = hton... |
**For TCP client side:**
Use gethostbyname to lookup dns name to IP, it will return a hostent structure. Let's call this returned value host.
hostent *host = gethostbyname(HOSTNAME_CSTR);
Fill the socket address structure:
sockaddr_in sock;
sock.sin_family = AF_INET;
sock.sin_port = hton... |
The property you need is location.hash. For example:<br /><br/>
location.hash = 'top'; //would jump to named anchor "top
I don't know how to do the nice scroll animation without the use of dojo or some toolkit like that, but if you just need it to jump to an anchor, location.hash should do it.
(tested on FF... |
The way you described is the only supported way to do "branching". And as you pointed out it is rather clunky. In VSS it's best to avoid branching alltogether as it will destroy your source history. |
<pre>
$ ulimit -c unlimited
$ gdb --pid=26426
(gdb) gcore
Saved corefile core.26426
(gdb) detatch
</pre> |
You could simply add some padding around the elements with CSS, e.g.
form input.a { margin-bottom: 1em } |
One option is to specify and XSLT template within your XML that (some) browsers will process allowing you to change the XML into XHTML with mark-up, colors etc. that shouldn't affect consumers of the web service.
Once in XHTML you could simply add some padding around the elements with CSS, e.g.
form input.a { mar... |
One option is to specify a XSLT template within your XML that (some) browsers will process allowing you to include presentation with mark-up, CSS, colors etc. that shouldn't affect consumers of the web service.
Once in XHTML you could simply add some padding around the elements with CSS, e.g.
form input.a { margi... |
[Confluence][1] does this. Also exports to PDF.
[1]: http://www.atlassian.com/software/confluence/ |
scrollTop (IIRC) is where in the document the top of the page is scrolled to. scrollTo scrolls the page so that the top of the page is where you specify.
What you need here is some Javascript manipulated styles. Say if you wanted the div off-screen and scroll in from the right you would set the left attribute of the... |
This is what [MapReduce][1] was invented for. [Hadoop][2] is a cool java implementation.
[1]: http://en.wikipedia.org/wiki/MapReduce
[2]: http://hadoop.apache.org/ |
I have code from many, many years ago. In fact, I think I still have my first php script. If nothing else, it's a good way to see how much you have changed over time. |
The Symbol#to_proc function that Rails provides is really cool.
Instead of
Employee.collect { |emp| emp.name }
You can write:
Employee.collect(&:name) |
Just FYI, Google does not do any substring searches or truncation, right or left. They have a wildcard character * to find unknown words in a phrase, but not a word.
Google, along with most full-text search engines, sets up an inverted index based on the alphabetical order of words, with links to their source do... |
Here's my suggestion:
[Flags]
public enum ThreadAccess : int
{
TERMINATE = (0x0001),
SUSPEND_RESUME = (0x0002),
GET_CONTEXT = (0x0008),
SET_CONTEXT = (0x0010),
SET_INFORMATION = (0x0020),
QUERY_INFORMATION = (0x0040),
... |
According to this cheatsheet ( http://www.addedbytes.com/download/mod_rewrite-cheat-sheet-v2/png/ ) this should work
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1
Note that i don't have a way to test this so this should be taken as a pointer in the right di... |
It creates a SHA1 based random number generator (RNG), then Base64 encodes the next 20 bytes returned by the RNG.
I can't tell you why it does this however without some more context :-). |
System.Web.Mail is deprecated, but should still work. You'll be annoyed with warnings about it being obsolete, but the functionality still carries on... for the time being.
I would agree with others that the conversion to System.Net.Mail was very trivial. I doubt you'd have to re-write more than a line or two. |
that's not overload! that's HIDE! |
Thanks for your help, managed to sort it as follows:
<ItemGroup>
<LibraryFiles Include="$(LibrariesReleaseDir)\**\*.*" Exclude="$(LibrariesReleaseDir)\**\.svn\**" />
</ItemGroup>
Turns out the pattern matching basically runs on files, so you have to exclude everything BELOW the .svn directories... |
I think what you are looking for is Custom Type Descriptors.
You could read up a bit and get started here: http://www.codeproject.com/KB/miscctrl/bending_property.aspx
I am not sure you can do any control you want, but that article got me started on propertygrids. |
How to add a constant column when replicating a database? |
|sql-server|replication| |
I am using SQL Server 2000 and I have two databases that both replicate (transactional push subscription) to a single database. I need to know which database the records came from.
So I want to add a fixed column specified in the publication to my table so I can tell which database the row originated from.
How d... |
I am using SQL Server 2000 and I have two databases that both replicate (transactional push subscription) to a single database. I need to know which database the records came from.
So I want to add a fixed column specified in the publication to my table so I can tell which database the row originated from.
How d... |
<a href="http://www.steema.com/products/teechart/whatsnew.html">TeeChart</a>. I've been using this tool for a few years now, although it is not free (~500€) it is packed with features.<br>
What I prefer:
- axes scale automatically
- automatic colours for different series
- zoom by selecting an area with the mou... |
UTC/GMT would be consistent in distributed environment.
One important thing is that specify the datetimeKind after populating your DateTime property with the value from database.
dateTimeValueUtcKind = DateTime.SpecifyKind(dateTimeValue, DateTimeKind.Utc);
[See MSDN][1]
[1]: http://msdn.microsoft.c... |
Don't know how hidden this is, but I've found it useful when needing to make a Hash out of a one-dimensional array:
fruit = ["apple","red","banana","yellow"]
=> ["apple", "red", "banana", "yellow"]
Hash[*fruit]
=> {"apple"=>"red", "banana"=>"yellow"}
|
You can either do this server-side or client-side. It's not very processor intensive, but if you do it client side (using Javascript) there will be a noticeable lag. Most client side solutions revolve around Google Code's syntax highlighting engine. This seems to be the most popular one: [SyntaxHighlighter][1]
Se... |
Try this:
(add-hook 'text-mode-hook
(function
(lambda ()
(setq tab-width 4)
(define-key text-mode-map "\C-i" 'self-insert-command)
)))
That will make TAB always insert a literal TAB character with tab stops every 4 characters (but only in Text mode). If that's not... |
Could you set the focus somewhere else just before saving? |
Could you set the focus somewhere else just before saving?
You can do this by calling focus() on a UI element.
You could focus on whatever element invokes the "save". |
Could you set the focus somewhere else just before saving?
You can do this by calling focus() on a UI element.
You could focus on whatever element invokes the "save". If your trigger is LostFocus then you have to move the focus somewhere. Save has the advantage that it isn't modified and would make sense to the... |
`round(5.59, 1)` is working fine. The problem is that 5.6 cannot be represented exactly in binary floating point.
>>> 5.6
5.5999999999999996
>>>
As Vinko says, you can use string formatting to do rounding for display.
Python has a [module for decimal arithmetic][1] if you need that.
[1]: ... |
"is" is basically equivalent to the "isinst" IL operator -- which that article describes as fast. |
[http://wiki.rubyonrails.org/rails/pages/HowtoGenerateJSON][1]
[1]: http://wiki.rubyonrails.org/rails/pages/HowtoGenerateJSON |
It should be quick enough to not matter. If you are checking the type of an object enough for it to make a noticeable impact on performance you need to rethink your design |
Convert XML/HTML Entities into Unicode String in Python |
|python|html|entities| |
I'm doing some web scraping and sites frequently use HTML entities to represent non ascii characters. Does Python have a utility that takes a string with HTML entities and returns a unicode type?
For example:
I get back:
& #x01ce; (There is no space. I put that so Markdown won't interpret it)
which represent... |
I wouldn't think so, as obfuscating (as I understand it at least) will simply mess around with the method names to make it hard (but not impossible) to understand the code. This won't change the data of the actual key (which I'm guessing you have stored in constant somewhere).
If you just want to make it somewhat ... |
+1 for Lucene and FAST. Lucene has also been ported to .NET if you're interested in extending it.
http://incubator.apache.org/lucene.net/ |
How is 1.exe launched? If you can launch it using CreateProcess(), you can start the process in a suspended state, attach the debugger, then release the new process. |
When DllMain with fdwReason = DLL_PROCESS_DETACH parameter is called it means the DLL is unloaded by the application. This is the time before the destructor of global/static objects gets called. |
How can I efficiently build different versions of a component with one Makefile |
|makefile|dependencies| |
|dependencies|makefile| |
I hope I haven't painted myself into a corner. I've gotten what seems to be most of the way through implementing a Makefile and I can't get the last bit to work. I hope someone here can suggest a technique to do what I'm trying to do.
I have what I'll call "bills of materials" in version controlled files in a sour... |
If it don't support objects tags, then try the Embed tag instead:
http://www.mioplanet.com/rsc/embed_mediaplayer.htm
I don't know it if works, but it is worth a shot :) |
[Functional Java][1] offers first-class function values, immutable lists/arrays/streams, tuple types, either types, optional values (type-safe alternative to null). Works well in conjunction with Google Collections or the java.util collections.
It also provides handy concurrency abstractions like parallel strategies... |
[Functional Java][1] offers first-class function values, immutable lists/arrays, lazy/infinite streams, tuple types, either types, optional values (type-safe alternative to null). Works well in conjunction with Google Collections or the java.util collections.
It also provides handy concurrency abstractions like para... |
Sounds like replication is the best solution for this. After the initial sync the slave gets updates via the <a href="http://dev.mysql.com/doc/refman/5.0/en/binary-log.html">Binary Log</a>, thus not affecting the master DB at all.
<a href="http://dev.mysql.com/doc/refman/5.0/en/replication.html">More on replication... |
Here's a quick hack:
public Image AppendBorder(Image original, int borderWidth)
{
var borderColor = Color.White;
var newSize = new Size(
original.Width + borderWidth * 2,
original.Height + borderWidth * 2);
var img = new Bitmap(newSize.Width, newSize.... |
If you *really* must do this sort of thing, you should probably call operator new directly:
STRUCT* pStruct = operator new(sizeof(STRUCT) + nPaddingSize);
I believe calling it this way avoids calling constructors/destructors. |
You use a .desktop file for icons under linux. Where to put the icon depends on what distribution and what desktop environment you are using. Since I'm currently running Gnome on Fedora 9, I will answer it in those terms.
An example foo.desktop file would be:
[Desktop Entry]
Encoding=UTF-8
Generic... |
You use a .desktop file for icons under linux. Where to put the icon depends on what distribution and what desktop environment you are using. Since I'm currently running Gnome on Fedora 9, I will answer it in those terms.
An example foo.desktop file would be:
[Desktop Entry]
Encoding=UTF-8
Generic... |
Yes, it's Nothing in VB.NET, or null in C#.
The Nullable generic datatype give the compiler the possibility to assign a "Nothing" (or null" value to a value type. Without explicitally writing it, you can't do it.
[Nullable Types in C#][1]
[1]: http://msdn.microsoft.com/en-us/library/1t3y8s4s(VS.80).aspx |
I don't believe this is possible in Visual Studio. However, you should check out this nice product for splitting applications: [http://www.winsplit-revolution.com/][1]
[1]: http://www.winsplit-revolution.com/ |