instruction
stringlengths 0
30k
⌀ |
---|
Given the URL (single line):
http://test.example.com/dir/subdir/file.html
How can I extract the following parts using regular expressions:
1. The Subdomain (test)
2. The Domain (example.com)
3. The path without the file (/dir/subdir/)
4. The file (file.html)
5. The path with the file (/dir/subdir/file.html)
6. The URL without the path (http://test.example.com)
7. (add any other that you think would be useful)
The regex should work correctly even if I enter the following URL:
http://example.example.com/example/example/example.html
Thank you. |
The best I could come up with is to produce a matrix of sums of each pair, and then merge the rows together, a-la merge sort. I feel like I'm missing some simple insight that will reveal a much more efficient solution.
My algorithm, in Haskell:
matrixOfSums list = [[a+b | b <- list, b >= a] | a <- list]
sortedSums = foldl merge [] matrixOfSums
--A normal merge, save that we remove duplicates
merge xs [] = xs
merge [] ys = ys
merge (x:xs) (y:ys) = case compare x y of
LT -> x:(merge xs (y:ys))
EQ -> x:(merge xs (dropWhile (==x) ys))
GT -> y:(merge (x:xs) ys)
I found a minor improvement, one that's more amenable to lazy stream-based coding. Instead of merging the columns pair-wise, merge all of them at once. The advantage being that you start getting elements of the list immediately.
-- wide-merge does a standard merge (ala merge-sort) across an arbitrary number of lists
-- wideNubMerge does this while eliminating duplicates
wideNubMerge :: Ord a => [[a]] -> [a]
wideNubMerge ls = wideNubMerge1 $ filter (/= []) ls
wideNubMerge1 [] = []
wideNubMerge1 ls = mini:(wideNubMerge rest)
where mini = minimum $ map head ls
rest = map (dropWhile (== mini)) ls
betterSortedSums = wideNubMerge matrixOfSums
However, if you know you're going to use all of the sums, and there's no advantage to getting some of them earlier, go with '`foldl merge []`', as it's faster. |
Adobe Flex component events |
|apache-flex|actionscript-3| |
I have a component I wrote that display a filename, a thumbnail, and has a button to click on to load/play the file. The component is databound to a repeater. How can I make it so the button event fires to the main application and tells it which file to play? |
Maybe you should try including a fourth column, stating the table it came from, and then order and group by it:
SELECT A,B,C, "query 1" as origin FROM table WHERE field LIKE 'query%'
UNION
SELECT A,B,C, "query 2" as origin FROM table WHERE field LIKE '%query'
UNION
SELECT A,B,C, "query 3" as origin FROM table WHERE field LIKE '%query%'
GROUP BY origin, B ORDER BY origin, B ASC LIMIT 5 |
Also try out [visual svn][1] for your server if you want to avoid any command line work.
[1]: http://www.visualsvn.com/ |
Is there a WMI Redistributable Package? |
|wmi|windows|64-bit| |
I've been working on a project that accesses the WMI to get information about the software installed on a user's machine. We've been querying Win32_Product only to find that it doesn't exist in 64-bit versions of Windows because it's an ["optional component"][1].<br />
<br />
I know there are a lot of really good alternatives to querying the WMI for this information, but I've got a bit of a [vested interest][2] in finding out how well this is going to work out.<br />
<br />
What I want to know is if there's some kind of redistributable that can be packaged with our software to allow 64-bit users to get the WMI Installer Provider put onto their machines? Right now, they have to install it manually and the installation requires they have their Windows disc handy.<br />
<br />
Thanks, everyone.<br />
<br />
[1]: http://msdn.microsoft.com/en-us/library/aa392726(VS.85).aspx
[2]: http://www.codeplex.com/linq2wmi |
If it is just simple data contained in the Excel file you can read the data via ADO.NET. See the connection strings listed here:
[http://www.connectionstrings.com/?carrier=excel2007][1]
or
[http://www.connectionstrings.com/?carrier=excel][2]
-Ryan
[1]: http://www.connectionstrings.com/?carrier=excel2007
[2]: http://www.connectionstrings.com/?carrier=excel2007 |
If it is just simple data contained in the Excel file you can read the data via ADO.NET. See the connection strings listed here:
[http://www.connectionstrings.com/?carrier=excel2007][1]
or
[http://www.connectionstrings.com/?carrier=excel][2]
-Ryan
Update: then you can just read the worksheet via something like `select * from [Sheet1$]`
[1]: http://www.connectionstrings.com/?carrier=excel2007
[2]: http://www.connectionstrings.com/?carrier=excel2007 |
Just did a quick demo project that required managing some excel files. The .NET component from GemBox software was adequate for my needs. It has a free version with a few limitations.
[http://www.gemboxsoftware.com/GBSpreadsheet.htm][1]
[1]: http://www.gemboxsoftware.com/GBSpreadsheet.htm |
You could use jQuery. Here is an example: [http://www.jqueryplugins.com/plugins/view/61/][1]
[1]: http://www.jqueryplugins.com/plugins/view/61/ |
I think that depends on your window manager.
I'm a windows user, so this might be a wrong guess, but: Isn't there something called [X-Server][1] running on linux machines - at least on ones that might be interesting targets for VNC - that you can connect to with "X-Clients"?
VNC just takes everything that's on the screen and "tunnels it through your network". If I'm not totally wrong then the "X" protocol should give you the chance to use your client's desktop resolution.
Give [X-Server][1] on Wikipedia a try, that might give you a rough overview.
[1]: http://de.wikipedia.org/wiki/X-Server |
WF is available already in .net 3.0. It is a bit buggy though on the Designer-side in Visual Studio and can get quite messy. I use it on Sharepoint (where WF is pretty much your only option anyway) and overall I am quite satisfied with it, even though the learning curve is rather steep.
[Foundations of WF][1] is a good book to start with it, as they implement a complete solution from beginning to the end and explain the concepts behind it.
[1]: http://www.apress.com/book/view/1590597184 |
@Patrick you are assuming calling setValueInVector( v, idx ); at the end of the second loop is OK. If the code is to be identical, logically, it must be rewritten to somethng like this:
<pre><code>for( int idx = 0; idx < vectorLength; idx++) {
if( conditionAtVectorPosition( v, idx ) ) continue;
for( rowIdx = 0; rowIdx < n; rowIdx++ ) {
if( anotherConditionAtVector( v, rowIdx ) ) continue;
if( conditionAtMatrixRowCol( m, rowIdx, idx ) ) break;
}
if ( !conditionAtMatrixRowCol( m, rowIdx, idx ))
setValueInVector( v, idx );
}
</code></pre> |
Does this work for you? I extracted the inner loop into a method CheckedEntireMatrix (you can name it better than me) - Also my java is a bit rusty.. but I think it gets the message across
for( int idx = 0; idx < vectorLength; idx++) {
if( conditionAtVectorPosition( v, idx )
|| !CheckedEntireMatrix(v)) continue;
setValueInVector( v, idx );
}
private bool CheckedEntireMatrix(Vector v)
{
for( rowIdx = 0; rowIdx < n; rowIdx++ ) {
if( anotherConditionAtVector( v, rowIdx ) ) continue;
if( conditionAtMatrixRowCol( m, rowIdx, idx ) ) return false;
}
return true;
} |
You can set up VS.Net to break as soon as any exception occurs. Just run your project in debug mode, and it will stop as soon as the exception is thrown. Then you should have a better idea of why it isn't being caught.
Also, you can put some code in to [catch all unhandled exceptions][1]. Read the link for more info, but the basics are these two lines.
Application.ThreadException += new ThreadExceptionEventHandler(ThreadExceptionHandler);
// Catch all unhandled exceptions in all threads.
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
[1]: http://www.cubiczone.com/Articles/tabid/65/EntryID/24/Default.aspx |
How can I play compressed sound files in C# in a portable way? |
|c#|.net|mono|oggvorbis|audio| |
Is there a portable, not patent-restricted way to play compressed sound files in C# / .Net? <a href="http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx">System.Media.SoundPlayer</a> can handle only WAV, but those are typically to big to embed in a downloadable apllication. MP3 is protected with patents, so even if there was a fully managed decoder/player it wouldn't be free to redistribute. The best format available would seem to be OGG Vorbis, but I had no luck getting any C# Vorbis libraries to work (I managed to extract a raw PCM with <a href="http://anonsvn.mono-project.com/source/trunk/csvorbis/">csvorbis</a> but I don't know how to play it afterwards).
I neither want to distribute any binaries with my application nor depend on P/Invoke, as the project should run at least on Windows and Linux. I'm fine with bundling .Net assemblies as long as they are license-compatible with GPL.
[this question is a follow up to a <a href="http://lists.ximian.com/pipermail/mono-devel-list/2007-June/023863.html">mailing list discussion on mono-dev</a> mailing list a year ago] |
|c#|.net|mono|audio|oggvorbis| |
Is there a portable, not patent-restricted way to play compressed sound files in C# / .Net? I want to play short "jingle" sounds on various events occuring in the program.
<a href="http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx">System.Media.SoundPlayer</a> can handle only WAV, but those are typically to big to embed in a downloadable apllication. MP3 is protected with patents, so even if there was a fully managed decoder/player it wouldn't be free to redistribute. The best format available would seem to be OGG Vorbis, but I had no luck getting any C# Vorbis libraries to work (I managed to extract a raw PCM with <a href="http://anonsvn.mono-project.com/source/trunk/csvorbis/">csvorbis</a> but I don't know how to play it afterwards).
I neither want to distribute any binaries with my application nor depend on P/Invoke, as the project should run at least on Windows and Linux. I'm fine with bundling .Net assemblies as long as they are license-compatible with GPL.
[this question is a follow up to a <a href="http://lists.ximian.com/pipermail/mono-devel-list/2007-June/023863.html">mailing list discussion on mono-dev</a> mailing list a year ago] |
Oh and in reference to what Kibbee said; if you select Debug|Exceptions in VS and just click all the boxes in the 'thrown' column it should pick *everything* up AFAIK as a 'first chance exception', i.e. VS will indicate when the exception is *about* to be processed by everything else and break on the relevant code. This should help with debugging. |
Floating Point Number parsing: Is there a Catch All algorithm? |
|.net|c#|vb.net|asp.net| |
One of the fun parts of multi-cultural programming are numbers formats.
Americans use 10,000.50, Germans use 10.000,50, French use 10 000,50 etc.
My first approach would be: Take the string, parse it backwards, until I encounter a separator and use this as my decimal separator. The obvious flaw with that: 10.000 would be interpreted as 10.
Another approach: if the string contains 2 different non-numeric characters, use the last one as the decimal separator and discard the others. If I only have one, check if it occurs more than once and discard it if it does. It it only appears once, check if it has 3 digits after it. If yes, discard it, otherwise use it as decimal separator.
The obvious "best solution" would be to detect the User's culture or Browser, but that does not work if you have a Frenchman an an en-US Windows/Browser.
I just wonder: does the .net Framework contain some mythical black magic floating point parser that is better than Double.(Try)Parse() in trying to auto-detect the number format? |
|.net|c#|vb.net|asp.net|globalization| |
|c#|.net|asp.net|vb.net|internationalization|globalization| |
I'm not sure why you would want to do this in the first place. The resulting set for any moderately large values of x and y will be huge, and will grow exponentially as x and/or y get bigger.
Lets say your set of possible characters is the 26 lowercase letters of the alphabet, and you ask your application to generate all permutations where length = 5. Assuming you don't run out of memory you'll get 11,881,376 (i.e. 26 to the power of 5) strings back. Bump that length up to 6, and you'll get 308,915,776 strings back. These numbers get painfully large, very quickly.
Here's a solution I put together in Java. You'll need to provide two runtime arguments (corresponding to x and y). Have fun.
public class GeneratePermutations {
public static void main(String[] args) {
int lower = Integer.parseInt(args[0]);
int upper = Integer.parseInt(args[1]);
if (upper < lower || upper == 0 || lower == 0) {
System.exit(0);
}
for (int length = lower; length <= upper; length++) {
generate(length, "");
}
}
private static void generate(int length, String partial) {
if (length <= 0) {
System.out.println(partial);
} else {
for (char c = 'a'; c <= 'z'; c++) {
generate(length - 1, partial + c);
}
}
}
} |
The [scoring][1] contains the Inverse Document Frequency(IDF). If the term "John Smith" is in one partition, 0, 100 times and in partition 1, once. The score for searching for John Smith would be higher search in partition 1 as the term is more scarce.
To get round this you would wither have to have your index being over all partitions, or you would need to override the IDF.
[1]: http://hudson.zones.apache.org/hudson/job/Lucene-trunk/javadoc//org/apache/lucene/search/Similarity.html |
Because the score is determined on the Index if I am not completely mistaken. If you have different indexes (more/less or different data that was indexed), the score will differ:
[http://lucene.apache.org/java/docs/scoring.html][1]
(Warning: Contains Math :-))
[1]: http://lucene.apache.org/java/docs/scoring.html |
Longhorn213 almost has the right answer, but as as Sean Chambers and bdukes say, you should use
ctrl is IInterfaceToFind
instead of
ctrl.GetType() == aTypeVariable
The reason why is that if you use .GetType(), you will get the true type of an object, not necessarily what it can also be cast to in its inheritance/Interface implementation chain.
The most import thing to note is that **you have to use recursion** as longhorn213 points out or you may miss some of the controls on the page.
HOWEVER, I too would love to see if there more succinct way to do this with LINQ.
FYI Chris, the reason this doesn't work
if(ctrl is typeToFind)
Is because the type of typeToFind is actually System.RuntimeType. Only its value is the type you set it to, not the type of object it is. I hope that makes sense. |
Longhorn213 almost has the right answer, but as as Sean Chambers and bdukes say, you should use
ctrl is IInterfaceToFind
instead of
ctrl.GetType() == aTypeVariable
The reason why is that if you use .GetType(), you will get the true type of an object, not necessarily what it can also be cast to in its inheritance/Interface implementation chain.
The most import thing to note is that **you have to use recursion** as longhorn213 points out or you may miss some of the controls on the page.
HOWEVER, I too would love to see if there is a more succinct way to do this with LINQ.
FYI Chris, the reason this doesn't work
if(ctrl is typeToFind)
Is because the type of typeToFind is actually System.RuntimeType. Only its value is the type you set it to, not the type of object it is. I hope that makes sense. |
Longhorn213 almost has the right answer, but as as Sean Chambers and bdukes say, you should use
ctrl is IInterfaceToFind
instead of
ctrl.GetType() == aTypeVariable
The reason why is that if you use .GetType(), you will get the true type of an object, not necessarily what it can also be cast to in its inheritance/Interface implementation chain. Also, .GetType() will never return an abstract type/interface since you can't new up an abstract type or interface. GetType() returns concrete types only.
The most import thing to note is that **you have to use recursion** as longhorn213 points out or you may miss some of the controls on the page.
HOWEVER, I too would love to see if there is a more succinct way to do this with LINQ.
FYI Chris, the reason this doesn't work
if(ctrl is typeToFind)
Is because the type of the variable typeToFind is actually System.RuntimeType. You've only set its value to the type you are looking for. Example, if you set a string's value to "foo", its type is still string not "foo". I hope that makes sense. It's very easy to get confused when working with types. |
Longhorn213 almost has the right answer, but as as Sean Chambers and bdukes say, you should use
ctrl is IInterfaceToFind
instead of
ctrl.GetType() == aTypeVariable
The reason why is that if you use .GetType(), you will get the true type of an object, not necessarily what it can also be cast to in its inheritance/Interface implementation chain. Also, .GetType() will never return an abstract type/interface since you can't new up an abstract type or interface. GetType() returns concrete types only.
The reason this doesn't work
if(ctrl is typeToFind)
Is because the type of the variable typeToFind is actually System.RuntimeType. You've only set its value to the type you are looking for. Example, if you set a string's value to "foo", its type is still string not "foo". I hope that makes sense. It's very easy to get confused when working with types. I'm chronically confused when working with them.
The most import thing to note about longhorn213's answer is that **you have to use recursion** or you may miss some of the controls on the page.
Although we have a working solution here, I too would love to see if there is a more succinct way to do this with LINQ.
|
|language-agnostic|regex|url| |
Easy-to-Use Regular Expression Support in C++? |
|windows|c++|regex|regularexpression| |
I'm looking for a robust, easy-to-use, regular expression evaluator for native C++, either platform-independent or Windows-specific.
Requirements:
- Can't use Boost or ACE regex libraries (unfortunately)
- Can't use .NET Regex (or any managed code)
The main requirement is that it should be standalone and open.
ANY help is appreciated.
Thanks! |
|c++|regex| |
|c++|regex|regular-expression| |
|c++|regex| |
If you need to you can create and drop temporary tables in procedures using the [Execute Immediate][1] command.
[1]: http://www.dbasupport.com/oracle/ora9i/execute_immediate.shtml |
Personally, developing a website that is high traffic perfomance based, I stay away from database transactions whenever possible. Obviously they are neccessary, so I use an ORM, and page level object variables to minimize the number of server side calls I have to make.
Nested transactions are an awesome way to minimize your calls, I steer in that direction whenever I can as long as they are quick queries that wont cause locking. NHibernate has been a savior in these cases. |
How do I bind a regular expression to a key combination in emacs? |
|emacs|lisp|regex|regular-expression| |
For context, I am something of an emacs newbie. I haven't used it for very long, but have been using it more and more (I like it a lot). Also I'm comfortable with lisp, but not super familiar with elisp.
What I need to do is bind a regular expression to a keyboard combination because I use this particular regex so often.
What I've been doing:
M-C-s ^.*Table\(\(.*\n\)*?GO\)
Note, I used newline above, but I've found that for isearch-forward-regex, you really need to replace the <code>\n</code> in your regex with <code>C-q Q-j</code>, which lets me match my expression across lines.
How can I bind this to a key combination? I vaguely understand that I need to create an elisp function which executes isearch-forward-regex with my expression, but I'm fuzzy on the details. I've searched google and found most documentation to be a tad confusing.
*How can I bind a regular expression to a key combination in emacs?* |
For context, I am something of an emacs newbie. I haven't used it for very long, but have been using it more and more (I like it a lot). Also I'm comfortable with lisp, but not super familiar with elisp.
What I need to do is bind a regular expression to a keyboard combination because I use this particular regex so often.
What I've been doing:
M-C-s ^.*Table\(\(.*\n\)*?GO\)
Note, I used newline above, but I've found that for isearch-forward-regex, you really need to replace the <code>\n</code> in your regex with <code>C-q Q-j</code>, which lets me match my expression across lines.
How can I bind this to a key combination? I vaguely understand that I need to create an elisp function which executes isearch-forward-regex with my expression, but I'm fuzzy on the details. I've searched google and found most documentation to be a tad confusing.
*How can I bind a regular expression to a key combination in emacs?*
---
@Mike Stone - Thanks for the information. I tried creating a macro like so:
C-x( M-C-s ^.*Table\(\(.*C-q C-J\)*?GO\) C-x)
This created my macro, but when I executed my macro I didn't get the same highlighting that I ordinarily get when I use <code>isearch-forward-regexp</code>. Instead it just jumped to the end of the next match of the expression. So that doesn't really work for what I need. Any ideas? |
Getting developers to use a wiki |
|documentation|wiki|mediawiki| |
I work on a complex application where different teams work on their own modules with a degree of overlap. A while back we got a Mediawiki instance set up, partly at my prompting. I have a hard job getting people to actually use it, let alone contribute.
I can see a lot of benefit in sharing information. It may at least reduce the times we reinvent the wheel.
The wiki is not very structured, but I'm not sure that is a problem as long as you can search for what you need.
Any hints? |
Easily, my good man.
for( int idx = 0; idx < vectorLength; idx++) {
if( conditionAtVectorPosition( v, idx ) ) continue;
for( rowIdx = 0; rowIdx < n; rowIdx++ ) {
if( anotherConditionAtVector( v, rowIdx ) ) continue;
if( conditionAtMatrixRowCol( m, rowIdx, idx ) ) break;
}
setValueInVector( v, idx );
} |
Easily, my good man.
for( int idx = 0; idx < vectorLength; idx++) {
if( conditionAtVectorPosition( v, idx ) ) continue;
for( rowIdx = 0; rowIdx < n; rowIdx++ ) {
if( anotherConditionAtVector( v, rowIdx ) ) continue;
if( conditionAtMatrixRowCol( m, rowIdx, idx ) ) break;
}
if( !conditionAtMatrixRowCol( m, rowIdx, idx ) )
setValueInVector( v, idx );
}
EDIT: Quite correct you are Anders. I've edited my solution to take that into account as well. |
Using ints is generally better than using shorts because java uses 32-bit values internally anyway (Even for bytes, unless in an array) so using ints will avoid unnecessary conversion to/from short values in the bytecode. |
If you're reading TPOP, you will next see how they make this search many times faster with different data structures and algorithms.
But you can make things a bit faster by replacing things like
for (i = 0; i < n; ++i)
foo(a[i]);
with
char **p = a;
for (i = 0; i < n; ++i)
foo(*p);
++p;
If there is a known value at the end of the array (e.g. NULL) you can eliminate the loop counter:
for (p = a; *p != NULL; ++p)
foo(*p)
Good luck, that's a great book! |
Sell the idea of using the wiki to the developers. You've identified some benefits, share those with the developers. If they can see that they'll get something of value out of it they'll start using it. |
Sell the idea of using the wiki to the developers. You've identified some benefits, share those with the developers. If they can see that they'll get something of value out of it they'll start using it.
Example advantages from [What Is a Wiki](http://www.oreillynet.com/pub/a/network/2006/07/07/what-is-a-wiki.html?page=2)
* Good for writing down quick ideas or longer ones, giving you more time for formal writing and editing.
* Instantly collaborative without emailing documents, keeping the group in sync.
* Accessible from anywhere with a web connection (if you don't mind writing in web-browser text forms).
* Your archive, because every page revision is kept.
* Exciting, immediate, and empowering--everyone has a say.
|
Run it through the query analyzer and see what the query plan is. My guess would be that the double root (ie. %ae%) searches are causing it do do a table scan when looking for the matching rows. Double root searches are inherently slow, as you can't use any kind of index to match them usually. |
What's your top feature request for Silverlight? |
|silverlight| |
I'll take away the obvious one here: mic and webcam support. Other than that, if you ran the Silverlight team, what would your highest priority be for Silverlight 3?
Disclaimer: If we get some good responses, I'll pass them along to folks I know on the Silverlight team. Is that cool? I mean, this site will be public soon enough, so they could find it if they wanted anyhow. |
|.net|silverlight| |
What's a good open source VoiceXML implementation? |
|speech-recognition|ivr|voip| |
I am trying to find out if it's possible to build a complete IVR application by cobbling together parts from open source projects. Is anyone using a non-commercial VoiceXML implementation to build speech-enabled systems? |
I'm completely inexperienced with yaws, but I have a troubleshooting suggestion: What happens if you remove the config file completely? If it still starts yaws without a config file, that could be a clear sign that something is being cached.
For what it's worth, with a quick 5 minutes of googling, I found no mention of any caching behavior. |
You can also pass the init parameters to the instance variables by position
# Abstract struct class
class Struct:
def __init__ (self, *argv, **argd):
if len(argd):
# Update by dictionary
self.__dict__.update (argd)
else:
# Update by position
attrs = filter (lambda x: x[0:2] != "__", dir(self))
for n in range(len(argv)):
setattr(self, attrs[n], argv[n])
# Specific class
class Point3dStruct (Struct):
x = 0
y = 0
z = 0
pt1 = Point3dStruct()
pt1.x = 10
print pt1.x
print "-"*10
pt2 = Point3dStruct(5, 6)
print pt2.x, pt2.y
print "-"*10
pt3 = Point3dStruct (x=1, y=2, z=3)
print pt3.x, pt3.y, pt3.z
print "-"*10
|
After adding `;.LNK` to the end of my `PATHEXT` environment variable, I can now execute shortcuts even without the preceding `./` notation. (Thanks bruceatk!)
I was also inspired by Steven's suggestion to create a little script that automatically aliases all the shortcuts in my `PATH` (even though I plan to stick with the simpler solution ;).
$env:path.Split( ';' ) |
Get-ChildItem -filter *.lnk |
select @{ Name="Path"; Expression={ $_.FullName } },
@{ Name="Name"; Expression={ [IO.Path]::GetFileNameWithoutExtension( $_.Name ) } } |
where { -not (Get-Alias $_.Name -ea 0) } |
foreach { Set-Alias $_.Name $_.Path } |
After adding `;.LNK` to the end of my `PATHEXT` environment variable, I can now execute shortcuts even without the preceding `./` notation. (Thanks bruceatk!)
I was also inspired by Steven's suggestion to create a little script that automatically aliases all the shortcuts in my `PATH` (even though I plan to stick with the simpler solution ;).
$env:path.Split( ';' ) |
Get-ChildItem -filter *.lnk |
select @{ Name='Path'; Expression={ $_.FullName } },
@{ Name='Name'; Expression={ [IO.Path]::GetFileNameWithoutExtension( $_.Name ) } } |
where { -not (Get-Alias $_.Name -ea 0) } |
foreach { Set-Alias $_.Name $_.Path } |
Longhorn213 almost has the right answer, but as as Sean Chambers and bdukes say, you should use
ctrl is IInterfaceToFind
instead of
ctrl.GetType() == aTypeVariable
The reason why is that if you use .GetType(), you will get the true type of an object, not necessarily what it can also be cast to in its inheritance/Interface implementation chain. Also, .GetType() will never return an abstract type/interface since you can't new up an abstract type or interface. GetType() returns concrete types only.
The reason this doesn't work
if(ctrl is typeToFind)
Is because the type of the variable typeToFind is actually System.RuntimeType, not the type you've set its value to. Example, if you set a string's value to "foo", its type is still string not "foo". I hope that makes sense. It's very easy to get confused when working with types. I'm chronically confused when working with them.
The most import thing to note about longhorn213's answer is that **you have to use recursion** or you may miss some of the controls on the page.
Although we have a working solution here, I too would love to see if there is a more succinct way to do this with LINQ.
|
Given that the exception is a DllNotFoundException, you might want to try checking the HardwareID.dll with [Dependency Walker][1] BEFORE installing any dev tools on the Vista install to see if there is in fact a dependency missing.
[1]: http://www.dependencywalker.com/ |
It's not really the languages that are OO, it's the code.
It is possible to write object-oriented C code (with structs and even function pointer members, if you wish) and I have seen some pretty good examples of it. (Quake 2/3 SDK comes to mind.) It is also definitely possible to write procedural (i.e. non-OO) code in C++.
Given that, I'd say it's the language's support for writing good OO code that makes it an "Object Oriented Language." I would never bother with using function pointer members in structs in C, for example, for what would be ordinary member functions; therefore I will say that C is not an OO language.
(Expanding on this, one could say that Python is not object oriented, either, with the mandatory "self" reference on every step and constructors called __init__, whatnot; but that's a Religious Discussion.) |
We ended up using Oracle XE. Install client, install express, reboot, it just works. |
From Linq in Action
> Microsoft has a Query Visualizer tool that can be downloaded separetly from VS 2008. it is at [http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx][1]
[1]: http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx |
Rails requires RubyGems >= 0.9.4. Please install RubyGems |
|ruby-on-rails|deployment|rubygems| |
I'm deploying to Ubuntu slice on slicehost, using Rails 2.1.0 (from gem)
If I try mongrel_rails start or script/server I get error:
> Rails requires RubyGems >= 0.9.4. Please install RubyGems
When I type `gem-v` i have 1.2.0. Any quick tips on what to look at to fix? |
Converting bool to text in C++ |
RDoc uses SimpleMarkup so it's fairly simple to create lists, etc. using *, - or a number. It also treats lines that are indented at the same column number as part of the same paragraph until there is an empty line which signifies a new paragraph. Do you have a few examples of comments you want RDoc'ed so we could show you how to do them and then you could extrapolate that for the rest of your comments? |
iPhone app in landscape mode |
|iphone| |
What's the best way to create an iPhone application that runs in landscape mode from the start, regardless of the position of the device? Both programmatically and using the Interface Builder. |
The best way to deploy video on the web is using Flash - it's much easier to embed cleanly into a web page and will play on more or less any browser and platform combination. The only reason to use Windows Media Player is if you're streaming content and you need extraordinarily strong digital rights management, and even then providers are now starting to use Flash even for these. See BBC's iPlayer for a superb example.
I would suggest that you switch to Flash even for internal use. You never know who is going to need to access it in the future, and this will give you the best possible future compatibility. |
If the fact that the first button is used by default is consistent across browsers, why not put them the right way round in the source code, then use CSS to switch their apparent positions? float them left and right to switch them around visually, for example. |
The difference between 12.345 in French and English is a factor of 1000. If you supply an expected range where max < 1000*min, you can easily guess.
Take for example the height of a person (including babies and children) in mm.
By using a range of 200-3000, an input of 1.800 or 1,800 can unambiguously be interpreted as 1 meter and 80 centimeters, whereas an input of 912.300 or 912,300 can unambiguously be interpreted as 91 centimeters and 2.3 millimeters. |
Yahoo uses a method called Sender ID, which can be configured at [The SPF Setup Wizard][1] and entered in to your DNS. Also one of the important ones for Exchange, Hotmail, AOL, Yahoo, and others is to have a Reverse DNS for your domain. Those will knock out most of the issues. However you can never prevent a person intentionally blocking your or custom rules.
[1]: http://old.openspf.org/wizard.html?mydomain=stackoverflow.com |
While you haven't said what you're storing, and you may have a great reason for doing so, often the answer is 'as a filesystem reference' and the actual data is on the filesystem somewhere.
<http://www.onlamp.com/pub/a/onlamp/2002/07/11/MySQLtips.html> |
[ElementTree][1] has a nice pythony API. I think it's even shipped as part of python 2.5
It's in pure python and as I say, pretty nice, but if you wind up needing more performance, then [lxml][2] exposes the same API and uses libxml2 under the hood. You can theoretically just swap it in when you discover you need it.
[1]: http://effbot.org/zone/element-index.htm
[2]: http://codespeak.net/lxml/ |
I've been working on a project that accesses the WMI to get information about the software installed on a user's machine. We've been querying Win32_Product only to find that it doesn't exist in 64-bit versions of Windows because it's an ["optional component"][1].
I know there are a lot of really good alternatives to querying the WMI for this information, but I've got a bit of a [vested interest][2] in finding out how well this is going to work out.
What I want to know is if there's some kind of redistributable that can be packaged with our software to allow 64-bit users to get the WMI Installer Provider put onto their machines? Right now, they have to install it manually and the installation requires they have their Windows disc handy.
Thanks, everyone.
[1]: http://msdn.microsoft.com/en-us/library/aa392726(VS.85).aspx
[2]: http://www.codeplex.com/linq2wmi |
|windows|64-bit|wmi| |
I've been working on a project that accesses the WMI to get information about the software installed on a user's machine. We've been querying Win32_Product only to find that it doesn't exist in 64-bit versions of Windows because it's an ["optional component"][1].
I know there are a lot of really good alternatives to querying the WMI for this information, but I've got a bit of a [vested interest][2] in finding out how well this is going to work out.
What I want to know is if there's some kind of redistributable that can be packaged with our software to allow 64-bit users to get the WMI Installer Provider put onto their machines? Right now, they have to install it manually and the installation requires they have their Windows disc handy.
Thanks, everyone.
Edit:
> You didn't mention for what OS, but the WMI Redistributable Components version 1.0 definitely exists.
For Operation System, we've been using .NET 3.5 so we need packages that will work on XP64 and 64bit versions of Windows Vista.
[1]: http://msdn.microsoft.com/en-us/library/aa392726(VS.85).aspx
[2]: http://www.codeplex.com/linq2wmi |
I would start with:
- [A Visual Guide to Version Control][1]
- [Wikipedia][2]
Then once you have read up on it, download and install [SVN][3], [TortoiseSVN][4] and skim the first few chapters of the [book][5] and get started.
[1]: http://betterexplained.com/articles/a-visual-guide-to-version-control/
[2]: http://en.wikipedia.org/wiki/Revision_control
[3]: http://subversion.tigris.org/
[4]: http://tortoisesvn.tigris.org/
[5]: http://svnbook.red-bean.com/ |
Eric Sink has a [good overview of source control][1]. There are also some [existing][2] [questions][3] here on SO.
[1]: http://www.ericsink.com/scm/source_control.html
[2]: http://stackoverflow.com/questions/871/why-is-git-better-than-subversion
[3]: http://stackoverflow.com/questions/2658/version-control-getting-started |
The ["Napkin Look & Feel"][1] for Java is really cool for prototyping. An actual, functioning, clickable app that looks like it was drawn on a napkin. Check out this screenshot:
![Napkin Look and Feel][2]
Seriously, how cool is that?
[1]: http://napkinlaf.sourceforge.net/
[2]: http://napkinlaf.sourceforge.net/NapkinButtons.jpg |
If you are working by yourself in a Windows environment, then the [single user license][1] for SourceGear's Vault is free.
[1]: http://www.sourcegear.com/faq.html |
Partial methods have been introduced for similar reasons to why partial classes were in .Net 2.
A partial class is one that can be split across multiple files - the compiler builds them all into one file as it runs.
The advantage for this is that Visual Studio can provide a graphical designer for part of the class while coders work on the other.
The most common example is the Form designer. Developers don't want to be positioning buttons, input boxes, etc by hand most of the time.
* In .Net 1 it was auto-generated code in a `#region` block
* In .Net 2 these became separate designer classes - the form is still one class, it's just split into one file edited by the developers and one by the form designer
This makes maintaining both much easier. Merges are simpler and there's less risk of the VS form designer accidentally undoing coders' manual changes.
In .Net 3.5 Linq has been introduced. Linq has a DBML designer for building your data structures, and that generates auto-code.
The extra bit here is that code needed to provide methods that developers might want to fill in.
As developers will extend these classes (with extra partial files) they couldn't use abstract methods here.
The other issue is that most of the time these methods wont be called, and calling empty methods is a waste of time.
Empty methods [are not optimised out](http://stackoverflow.com/questions/11783/in-net-will-empty-method-calls-be-optimized-out).
So Linq generates empty partial methods. If you don't create your own partial to complete them the C# compiler will just optimise them out.
So that it can do this partial methods always return void.
If you create a new Linq DBML file it will auto-generate a partial class, something like
[System.Data.Linq.Mapping.DatabaseAttribute(Name="MyDB")]
public partial class MyDataContext : System.Data.Linq.DataContext
{
...
partial void OnCreated();
partial void InsertMyTable(MyTable instance);
partial void UpdateMyTable(MyTable instance);
partial void DeleteMyTable(MyTable instance);
...
Then in your own partial file you can extend this:
public partial class MyDataContext
{
partial void OnCreated() {
//do something on data context creation
}
}
If you don't extend these methods they get optimised right out.
Partial methods can't be public - as then they'd have to be there for other classes to call. If you write your own code generators I can see them being useful, but otherwise they're only really useful for the VS designer.
The example I mentioned before is one possibility:
//this code will get optimised out if no body is implemented
partial void DoSomethingIfCompFlag();
#if COMPILER_FLAG
//this code won't exist if the flag is off
partial void DoSomethingIfCompFlag() {
//your code
}
#endif
Another potential use is if you had a large and complex class spilt across multiple files you might want partial references in the calling file. However I think in that case you should consider simplifying the class first. |
Max length for html text areas |
|javascript|html| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.