instruction
stringlengths 0
30k
⌀ |
---|
Does git have anything like `svn propset svn:keywords` or pre-/post-commit hooks? |
|svn|version-control|git| |
Not sure if this is what you are after but you can [search source code on Google][1].
Follow the link for a search on ['function:reduce() lang:python'][2] on Google Code search
At first glance the following projects use <code>reduce()</code>
<ul>
<li>MoinMoin</li>
<li>Zope</li>
<li>Numeric</li>
<li>ScientificPython</li>
</ul>
etc. etc. but then these are hardly surprising since they are huge projects.
The functionality of reduce can be done using function recursion which I guess Guido thought was more explicit.
[1]: http://www.google.com/codesearch/
[2]: http://www.google.com/codesearch?q=function%3Areduce()+lang%3Apython&hl=en&btnG=Search+Code |
Edit: Totally read the question wrong at first - ignore my first (now gone) answer. :)
I changed the keyboard mapping for CTRL-SHIFT-C from bringing up the Class View to closing all document windows - something I use several orders of magnitude more often - and then I just clear my workspace before closing a solution. |
I've been using Aptana/Eclipse/RadRails, but if I were to do it again, I'd definitely try NetBeans. Aptana has been a major headache.
I've never used IronRuby, but that might make you feel more at home. |
Or you can close all open document from the Window menu before closing VS. |
The Netbeans IDE is a good, all around editor for many languages. I'm pretty sure the 6.5 beta has support for Ruby on Rails, along with Javascript and a few other web languages. It's worth checking out [(Netbeans.org)][1].
[1]: http://www.netbeans.org "Netbeans.org" |
[Aptana Studio][1]
I use it for all web development - HTML, CSS, PHP, JavaScript, Rails...
[1]: http://www.aptana.com/ |
[Aptana Studio][1]
I use it for all web development - HTML, CSS, PHP, JavaScript, Rails...
EDIT: For full disclosure, I'm biased toward Aptana and RadRails as I know a few members of the original RadRails dev team.
[1]: http://www.aptana.com/ |
I have an old Python implementation of [pipegrep][1] that uses reduce and the glob module to build a list of files to process:
files = []
files.extend(reduce(lambda x, y: x + y, map(glob.glob, args)))
I found it handy at the time, but it's really not necessary, as something similar is just as good, and probably more readable
files = []
for f in args:
files.extend(glob.glob(f))
[1]: http://examples.oreilly.com/upt2/split/pipegrep |
[Sapphire in Steel](http://www.sapphiresteel.com/) integrates with Visual Studio. |
It's very complex matter indeed.
When you hit TAB focus jumps to another control only when these controls belong to a Modal Dialog Box. In fact there are some buttons like ESC, LEFT, RIGHT, DOWN, UP, TAB which modal dialog message function treats in a special way. If you want these keys to behave in similar way with modeless dialog box or any other window you should change you message processing function and use IsDialogMessage inside. You'll find more information about [IsDialogMessage][1] function in MSDN also to better understand this stuff you may check as well [Dialog Boxes][2] section.
Good luck!
[1]: http://msdn.microsoft.com/en-us/library/ms645498(VS.85).aspx
[2]: http://msdn.microsoft.com/en-us/library/ms632588(VS.85).aspx |
|encryption|passwords|php| |
What is the fastest, yet secure way to encrypt passwords in PHP, and for which ever method you choose is it portable?<br />In other words if I later migrate my website to a different server will my passwords continue to work?<br />The method I am using now I was told is dependent on the exact versions of the libraries installed on the server. |
|encryption|passwords| |
What is the fastest, yet secure way to encrypt passwords in (PHP Prefered), and for which ever method you choose is it portable?<br />In other words if I later migrate my website to a different server will my passwords continue to work?<br />The method I am using now I was told is dependent on the exact versions of the libraries installed on the server. |
If you are choosing an encryption method for your login system then speed is not your friend, Jeff had a to-and-frow with Thomas Ptacek about passwords and the [conclusion][1] was that you should use the slowest, most secure encryption method you can afford to.
[1]: http://www.matasano.com/log/958/enough-with-the-rainbow-tables-what-you-need-to-know-about-secure-password-schemes/ |
If you are choosing an encryption method for your login system then speed is not your friend, Jeff had a to-and-frow with Thomas Ptacek about passwords and the [conclusion][1] was that you should use the slowest, most secure encryption method you can afford to.
>From Thomas Ptacek's blog:
>Speed is exactly what you don’t want in a password hash function.
>
>Modern password schemes are attacked with incremental password crackers.
>
>Incremental crackers don’t precalculate all possible cracked passwords. They consider each password hash individually, and they feed their dictionary through the password hash function the same way your PHP login page would. Rainbow table crackers like Ophcrack use space to attack passwords; incremental crackers like John the Ripper, Crack, and LC5 work with time: statistics and compute.
>
>The password attack game is scored in time taken to crack password X. With rainbow tables, that time depends on how big your table needs to be and how fast you can search it. With incremental crackers, the time depends on how fast you can make the password hash function run.
>
>The better you can optimize your password hash function, the faster your password hash function gets, the weaker your scheme is. MD5 and SHA1, even conventional block ciphers like DES, are designed to be fast. MD5, SHA1, and DES are weak password hashes. On modern CPUs, raw crypto building blocks like DES and MD5 can be bitsliced, vectorized, and parallelized to make password searches lightning fast. Game-over FPGA implementations cost only hundreds of dollars.
[1]: http://www.matasano.com/log/958/enough-with-the-rainbow-tables-what-you-need-to-know-about-secure-password-schemes/ |
I would use Javascript to submit the form. The function would be triggered by the OnKeyPress event of the form element, and would detect whether the Enter key was selected. If this is the case, it will submit the form.
Here are two pages that give techniques on how to do this: [1][1], [2][2]. Based on these, here is an example of usage (based on [here][1]):
<SCRIPT TYPE="text/javascript"><!--
function submitenter(myfield,e) {
var keycode;
if (window.event) {
keycode = window.event.keyCode;
} else if (e) {
keycode = e.which;
} else {
return true;
}
if (keycode == 13) {
myfield.form.submit();
return false;
} else {
return true;
}
}
//--></SCRIPT>
<INPUT NAME="MyText" TYPE="Text" onKeyPress="return submitenter(this,event)" />
[1]: http://www.htmlcodetutorial.com/forms/index_famsupp_157.html
[2]: http://www.java2s.com/Code/JavaScript/Form-Control/SubmitaformViaEnter.htm |
Can anyone point me to a good tutorial on creating a bootable Linux CD from scratch?
I need help with a fairly specialized problem: my firm sells an expansion card that requires custom firmware. Currently we use an extremely old live CD image of RH7.2 that we update with current firmware. Manufacturing puts the cards in a machine, boots off the CD, the CD writes the firmware, they power off and pull the cards. Because of this cycle, it's essential that the CD boot and shut down as quickly as possible.
The problem is that with the next generation of cards, I have to update the CD to a 2.6 kernel. It's easy enough to acquire a pre-existing live CD - but those all are designed for showing off Linux on the desktop - which means they take forever to boot.
Can anyone fix me up with a current How-To?
---
###Update:
So, just as a final update for anyone reading this later - the tool I ended up using was "livecd-creator".
My reason for choosing this tool was that it is available for RedHat-based distributions like CentOs, Fedora and RHEL - which are all distributions that my company supports already. In addition, while the project is very poorly documented it is extremely customizable. I was able to create a minimal LiveCD and edit the boot sequence so that it booted directly into the firmware updater instead of a bash shell.
The whole job would have only taken an hour or two if there had been a README explaining the configuration file!
|
I think this would be an excellent feature request for Microsoft: Create an abstract base class attribute `CompilerExecutedAttribute` that the compiler processes in some manner or that can influence the compiling process. Then we could inherit from this attribute and implement different operations, e.g. emit an error or a warning. |
The SQL Profiler tool is only available with the Standard and Enterprise version of SQL Server, however, all version can be profiled using the tool.
Source: [http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx][1]
[1]: http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx |
My colleague has been using [WpfDiagram](http://www.mindfusion.org/wpfdiagram.html) from MindFusion for the last two weeks and says that it's an excellent product. |
If you're just looking for low-level database access—you feed it and SQL string (optionally with place-holders and bind values) and it runs your query and gives you back the results—then yes, <a href="http://search.cpan.org/dist/DBI/">DBI</a> is your best bet, by far.
If you want a higher-level interface (i.e., one that requires little or no use of raw SQL in your code) then there are several ORMs (<a href="http://en.wikipedia.org/wiki/Object-relational_mapping">object-relational mappers</a>) available for Perl. Check out the <a href="http://www.perlfoundation.org/perl5/index.cgi?orm">ORM</a> page at the Perl Foundation's Perl 5 wiki for more information and links. (If you want help choosing among them or have specific questions, you could narrow the focus of this question or perhaps post another one.)
P.S. @Matthew Watson - <a href="http://search.cpan.org/dist/Rose-DB/">Rose::DB</a> is not an ORM; <a href="http://search.cpan.org/dist/Rose-DB-Object/">Rose::DB::Object</a> is. |
It's very complex matter indeed.
When you hit TAB focus jumps to another control only when these controls belong to a Modal Dialog Box. In fact there are some buttons like ESC, LEFT, RIGHT, DOWN, UP, TAB which modal dialog message function treats in a special way. If you want these keys to behave in similar way with modeless dialog box or any other window you should change you message processing function and use IsDialogMessage inside. You'll find more information about [IsDialogMessage][1] function in MSDN also to better understand this stuff you may check as well [Dialog Boxes][2] section.
And, as was mentioned before, you should set [WS_TABSTOP][3] and [WS_GROUP][3] styles when needed.
Good luck!
[1]: http://msdn.microsoft.com/en-us/library/ms645498(VS.85).aspx
[2]: http://msdn.microsoft.com/en-us/library/ms632588(VS.85).aspx
[3]: http://msdn.microsoft.com/en-us/library/czada357(VS.80).aspx |
To optimize that code the best bet would be to rewrite the strcmp routine since you are only checking for equality and don't need to evaluate the entire word.
Other than that you can't do much else. You can't sort as it appears you are looking for text within a larger text. Binary search won't work either since the text is unlikely to be sorted.
My 2p (C-psuedocode):
wrd_end = wrd_ptr + wrd_len;
arr_end = arr_ptr - wrd_len;
while (arr_ptr < arr_end)
{
wrd_beg = wrd_ptr; arr_beg = arr_ptr;
while (wrd_ptr == arr_ptr)
{
wrd_ptr++; arr_ptr++;
if (wrd_ptr == wrd_en)
return wrd_beg;
}
wrd_ptr++;
} |
Try both NetBeans and RadRails for maybe a week each, then you can find which works best for you. The best advice is to learn your tool. If you are not checking out something new about your editor, something that could potentially save you time (regexp, etc) then you are doing yourself a huge disservice.
I have been using Eclipse/Aptana/RadRails and unlike Gaius have been pretty happy with it.
I recommend the Eclipse IDE for Java Developers from Eclipse Downloads: http://www.eclipse.org/downloads/
Then grab Aptana Studio, following these <a href="http://www.aptana.com/docs/index.php/Plugging_Aptana_into_an_existing_Eclipse_configuration#Eclipse_3.4_Instructions">instructions</a>.
When Eclipse restarts Aptana will have a view, click on rad rails and you are good to go. Just make sure you have ruby installed already, or it becomes a pain to resolve.
|
How to apply multiple styles in WPF |
|.net|wpf|styles| |
In WPF, how would I apply multiple styles to a `FrameworkElement`? For instance, I have a control which already has a style. I also have a separate style which I would like to add to it without blowing away the first one. The styles have different TargetTypes, so I can't just extend one with the other. |
What is the best way to replicate a version control repository? |
|version-control|cvs| |
Here is the scenario that I have. I have a cvs repository in one location (A) and I want to replicate it and keep it in sync with a repository in another location(B). This would be a single directional sync from A to B. What is the best way to do this? If it is not really feasible in CVS then which source code control system would you recommend to accomplish this? Thanks |
Browsing through the git documentation, I can't see anything analogous to SVN's commit hooks or the "propset" features that can, say, update a version number or copyright notice within a file whenever it is committed to the repository.
Are git users expected to write external scripts for this sort of functionality (which doesn't seem out of the question) or have I just missed something obvious?
*Edit* : Just to be clear, I'm more interested in, e.g.,
svn propset svn:keywords "Author Date Id Revision" expl3.dtx
where a string like this:
$Id: expl3.dtx 780 2008-08-30 12:32:34Z morten $
is kept up-to-date with the relevant info whenever a commit occurs. |
Visual Studio 2005/2008: How can you share/force all developers to use the same formatting rulles? |
|visual-studio|formatting| |
I would like to have all developers on my team to use the same rules for formatting code. Can I have visual studio look to a common place for these rules? |
I would like to have all developers on my team to use the same rules for formatting code. Can I have visual studio look to a common place for these rules?
I would like to not rely on export/import settings as that brings many settings along. I (for example) don't care what font colors the developer uses when typing, I just want similar formatting. Can you import a subset of settings? |
I would like to have all developers on my team to use the same rules for formatting several types of code (ASPX, CSS, JavaScript, C#). Can I have visual studio look to a common place for these rules?
I would like to not rely on export/import settings as that brings many settings along. I (for example) don't care what font colors the developer uses when typing, I just want similar formatting. Can you import a subset of settings? |
1. The question is not really related to checked vs. unchecked debate, the same applies to both exception types.
2. Between the point where the ConstraintViolationException is thrown and the point, where we want to handle the violation by displaying a nice error message is a large number of method calls on the stack that should abort immediately and shouldn't care about the problem. That makes the exception mechanism the right choice as opposed to redesigning the code from exceptions to return values.
3. In fact, using an unchecked exception instead of a checked exception is a natural fit, since we really want all intermediate methods on the call stack to _ignore_ the exception and _not handle it_ .
4. If we want to handle the "unique name violation" only by displaying a nice error message (error page) to the user, there's not really a need for a specific DuplicateUsernameException. This will keep the number of exception classes low. Instead, we can create a MessageException that can be reused in many similar scenarios.
As soon as possible we catch the ConstraintViolationException and convert it to a MessageException with a nice message. It's important to convert it soon, when we can be sure, it's really the "unique user name constraint" that was violated and not some other constraint.
Somewhere close to the top level handler, just handle the MessageException in a different way. Instead of "we logged your problem but for now you're hosed" simply display the message contained in the MessageException, no stack trace.
The MessageException can take some additional constructor parameters, such as a detailed explanation of the problem, available next action (cancel, go to a different page), icon (error, warning)...
The code may look like this
// insert the user
try {
hibernateSession.save(user);
} catch (ConstraintViolationException e) {
throw new MessageException("Username " + user.getName() + " already exists. Please choose a different name.");
}
In a totally different place there's a top exception handler
try {
... render the page
} catch (MessageException e) {
... render a nice page with the message
} catch (Exception e) {
... render "we logged your problem but for now you're hosed" message
}
|
The main problem with PHP sessions and security (besides session hijacking) comes with what environment you are in. By default PHP stores the session data in a file in the OS's temp directory. Without any special thought or planning this is a world readable directory so all of your session information is public to anyone with access to the server.
As for maintaining sessions over multiple servers. At that point it would be better to switch PHP to user handled sessions where it calls your provided functions to CRUD (create, read, update, delete) the session data. At that point you could store the session information in a database or memcache like solution so that all application servers have access to the data.
Storing your own sessions may also be advantageous if you are on a shared server because it will let you store it in the database which you often times have more control over then the filesystem. |
I also think that #2 is the best bet, though I would be sure to wrap it in a transaction in case something goes wrong mid-update.
An alternative (since you asked) to updating the Unique Index values with different values would be to update all of the other values in the rows to that of the other row. Doing this means that you could leave the Unique Index values alone, and in the end, you end up with the data that you want. Be careful though, in case some other table references this table in a Foreign Key relationship, that all of the relationships in the DB remain intact. |
I'm with Peter. Developer don't seem to understand passwords. We all pick (and I'm guilty of this too) MD5 or SHA1 because they are fast. Thinking about it ('cuz someone recently pointed it out to me) that doesn't make any sense. We should be picking a hashing algorithm that's stupid slow. I mean, on the scale of things, a busy site will hash passwords what? every 1/2 minute? Who cares if it take 0.8 seconds vs 0.03 seconds server wise? But that extra slowness is huge to prevent all types of common brute-forcish attacks.
From my reading, bcrypt is specifically designed for secure password hashing. It's based on blowfish, and there are many implementation.
For PHP, check out PHPPass <http://www.openwall.com/phpass/>
For anyone doing .NET, check out BCrypt.NET <http://derekslager.com/blog/posts/2007/10/bcrypt-dotnet-strong-password-hashing-for-dotnet-and-mono.ashx> |
I've found that using the recipients real first and last name in the body is a sure fire way of getting through a spam filter. |
This works for me in firefox and IE
<object id="mediaplayer" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701" standby="loading microsoft windows media player components..." type="application/x-oleobject" width="320" height="310">
<param name="filename" value="./test.wmv">
<param name="animationatstart" value="true">
<param name="transparentatstart" value="true">
<param name="autostart" value="true">
<param name="showcontrols" value="true">
<param name="ShowStatusBar" value="true">
<param name="windowlessvideo" value="true">
<embed src="./test.wmv" autostart="true" showcontrols="true" showstatusbar="1" bgcolor="white" width="320" height="310">
</object> |
If you're just looking for low-level database access—you feed it and SQL string (optionally with place-holders and bind values) and it runs your query and gives you back the results—then yes, <a href="http://search.cpan.org/dist/DBI/">DBI</a> is your best bet, by far.
If you want a higher-level interface (i.e., one that requires little or no use of raw SQL in your code) then there are several ORMs (<a href="http://en.wikipedia.org/wiki/Object-relational_mapping">object-relational mappers</a>) available for Perl. Check out the <a href="http://www.perlfoundation.org/perl5/index.cgi?orm">ORM</a> page at the Perl Foundation's Perl 5 wiki for more information and links. (If you want help choosing among them or have specific questions, you could narrow the focus of this question or perhaps post another one.) |
Just to add briefly to [Ted Percival](#43262)'s comment above...
A hard disk drive will perform fastest if it is doing sequential writes or sequential reads, because the drive head doesn't need to move around.
SQL Server log files happen to be sequential, so if you dedicate a hard drive to ONLY the logs, you will see a noticeable performance improvement. That said, for smaller databases where performance is not an issue, it doesn't matter.
And as for [Nir](#43264)'s comment on drive failures -- hopefully you are handling that at a lower level, by putting both your data and logs on RAID arrays. |
If you are open to using third party profilers, I have used [xSQL Profiler][1] and it performed well enough.
[1]: http://www.xsqlsoftware.com/Product/xSQL_Profiler.aspx |
You don't need **any** SQL license to run the client tools (Management Studio, Profiler, etc). If your organization has a copy of the installation media for Developer, Standard, or Enterprise, you can install the client tools on your local machine under the same license.
If you're working solo, I would recommend [purchasing](http://www.microsoft.com/products/info/product.aspx?view=22&pcid=f544888c-2638-48ed-9f0f-d814e8b93ca0&crumb=catpage&catid=cd1daedd-9465-4aef-a7bf-8f5cf09a4dc0#HowToBuy) SQL Developer edition, it's only $50. |
Pin Emacs buffers to windows (for cscope) |
|emacs| |
For my day job, I live in Emacs. Utterly. I also have become pretty dependent on CScope to help me find things in the code.
Normally, I have 2 windows in a split (C-x 3):
![alt text][1]
And I use the right window for code buffers and the left window for the CScope search buffer. When you do a CScope search and select a result, it automatically updates the right-side window to show the buffer referred to by the result. This is all well and good, except that it causes me to lose my place in some other buffer that I was studying. Sometimes this is no biggie, because [C-s u] gets me back to where I was.
What would be better, though, is to have 3 split windows like this ([C-x 2] in the left window):
![alt text][2]
And have the bottom left window contain the CScope search buffer, and the top left window be the only buffer that CScope ever updates. That way, I can see my CScope searches and navigate around the code without losing the buffer I'm focused on.
Anyone know how I can do that?
[1]: http://bitthicket.com/files/emacs-2split.JPG
[2]: http://bitthicket.com/files/emacs-3split.jpg |
I would go with the file system approach. As noted by a few others, most web servers are built to send images from a file path. You'll have much higher performance if you don't have to write or stream out BLOB fields from the database. Having filesystem storage for the images makes it easier to setup static pages when the content isn't changing or you want limit the load on the database. |
Yes resources are still the best way to support multiple languages in the .NET environment. Because they are easy to reference and even easier to add new languages.
Site.resx
Site.en.resx
Site.en-US.resx
Site.fr.resx
etc...
So you are right still use the resource files. |
If you're doing something for yourself, or if you're doing just a prototype, or testing an idea... use the free style that script languages gives you.
After that: always think in objects, try to organize your work around the OO paradigm even if you're writing procedural stuff. Then, refactorize, refactorize, refactorize. |
Try changing the local security policy on that Vista box for "Local Policies\Security Options\Network Security: LAN manager authentication level" from “Send NTLMv2 response only” to “Send LM & NTLM - use NTLMv2 session security if negotiated”. |
No I have successfully done this with my Vista 64-bit machine. You may want to try using the IP Address of the machine and try connecting that way. Or maybe check out the log files on the Mac to see what the rejection error was. |
Ruby On Rails with Windows Vista - Best Setup? |
|rubyonrails|windows|ide| |
What do you think is the best set-up for RoR in a Win Vista environment? I've tried the radrails eclipse plug-in, and it just seemed too bulky for me, I've also started to just use Textpad and the command line, but I'm used to having somewhat of an IDE to work with.
Thanks for the help! |
|windows|ruby|ruby-on-rails|ide| |
How do I create a new Ruby on Rails application using MySQL instead of SQLite? |
|rubyonrails|mysql| |
I want to create my Rails application with MySQL, because I like it so much. How can I do that in the latest version of Rails? |
|ruby|mysql|ruby-on-rails| |
But I think you have to be very careful with it. If you will overuse this pattern, you will make very complicated design and even more complicated code.
Like in this example with TextEditor: if you have only one SpellChecker maybe it is not really necessary to use IoC ? Unless you need to write unit tests or something ...
Anyway: be reasonable. Design pattern are **good practices** but not Bible to be preached. Do not stick it everywhere. |
I can't say if this is overkill without knowing the details of your usage case, but consider creating a spreadsheet C to hold all data held in common between the two. Links can become dizzyingly complex as spreadsheets age, and having a shared data source might help clear up the confusion.
Perhaps even more "enterprise-y" is the concept of just pasting in all data that otherwise would be shared. That is the official best practice in my company, because external links have caused so much trouble with maintainability. It may seem cumbersome at first, but I've found it may just be the best way to promote maintainability in addition to ease of use, assuming you don't mind the manual intervention. |
flipdoubt: they are projects created originally in 2008. My suggestion if it's not working C# is to look in the Build Events tab and check the setting of the "Run the post-build event:" drop down. If it is set to 'When the build updates the project output' this might be your problem, try setting to 'On successful build'.
John.
|
When using CVS, I don't know any tools to do that other than files syncing. You can achieve that using tools like rsync (Unix) or xcopy/robocopy (Windows).
If you plan on migrating to Subversion, it provides a tool called svnsync that allows to sync a repository from another one. |
Thanks to everyone who answered. lomaxx, I spent the morning looking into using the external feature and it looks like this is the way to go. I was not aware of it, probably because it is not exactly prominent in Tortoise. |
http://msdn.microsoft.com/en-us/library/aa328348.aspx
You're looking for Enum.Parse. |
It's rather ugly:
StatusEnum MyStatus = (StatusEnum) Enum.Parse( typeof(StatusEnum), "Active", true );
I tend to simplify this with:
public static T ParseEnum<T>( string value )
{
return (T) Enum.Parse( typeof( T ), value, true );
}
Then I can do:
StatusEnum MyStatus = EnumUtil.ParseEnum<StatusEnum>("Active"); |
I would recommend you migrate from CVS to a proper distributed version control system such as [git][1], which will provide this sort of functionality very naturally.
Subversion also provides svnsync which does the same sort of thing.
[1]: http://git.or.cz |
Enum.Parse is your friend:
StatusEnum MyStatus = (StatusEnum)Enum.Parse(typeof(StatusEnum), "Active"); |
But you can extend from another.. take a look at the BasedOn property
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="3" />
</Style>
<Style x:Key="AlwaysVerticalStyle" TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
<Setter Property="VerticalAlignment" Value="Top" />
</Style> |
Converting a string to an enumeration value in C# |
|c#| |
What's the best way to convert a string to an enumeration value in C#?
I have an HTML select tag containing the values of an enumeration. When the page is posted, I want to pick up the value (which will be in the form of a string) and convert it to the enumeration value.
In an ideal world, I could do something like this:
StatusEnum MyStatus = StatusEnum.Parse("Active");
but that isn't valid code. |
|c#|enums| |
What's the best way to convert a string to an enumeration value in C#?
I have an HTML select tag containing the values of an enumeration. When the page is posted, I want to pick up the value (which will be in the form of a string) and convert it to the enumeration value.
In an ideal world, I could do something like this:
StatusEnum MyStatus = StatusEnum.Parse("Active");
but that isn't valid code. |
No, you were not dreaming. Python has a pretty excellent list comprehension system that lets you manipulate lists pretty elegantly, and depending on exactly what you want to accomplish, this can be done a couple of ways. In essence, what you're doing is saying "For item in list if criteria.matches", and from that you can just iterate through the results or dump the results into a new list.
I'm going to crib an example from [Dive Into Python][1] here, because it's pretty elegant and they're smarter than I am. Here they're getting a list of files in a directory, then filtering the list for all files that match a regular expression criteria.
> files = os.listdir(path)
> test = re.compile("test\.py$", re.IGNORECASE)
> files = [f for f in files if test.search(f)]
You could do this without regular expressions, for your example, for anything where your expression at the end returns true for a match. There are other options like using the filter() function, but if I were going to choose, I'd go with this.
Eric Sipple
[1]: http://diveintopython.org/functional_programming/filtering_lists.html |
How often do you need to check for changes and how large (in terms of row size) are the tables in the database? If you use the CHECKSUM_AGG(BINARY_CHECKSUM(*)) method suggested by Jeff, it will scan every row of the specified table. The NOLOCK hint helps, but on a large database, you are still hitting every row.
Have you considered going at this from a different angle? If you do not want to modify the schema to add triggers, (which makes a sense, it's not your database), have you considered working with the application vendor that does make the database?
They could implement an API that provides a mechanism for notifying accessory apps that data has changed. It could be as simple as writing to a notification table that lists what table and which row were modified. That could be implemented through triggers or application code. From your side, ti wouldn't matter, your only concern would be scanning the notification table on a periodic basis. The performance hit on the database would be far less than scanning every row for changes.
The hard part would be convincing the application vendor to implement this feature. Since this can be handles entirely through SQL via triggers, you could do the bulk of the work for them by writing and testing the triggers and then bringing the code to the application vendor. By having the vendor support the triggers, it prevent the situation where your adding a trigger inadvertently replaces a trigger supplied by the vendor. |
How often do you need to check for changes and how large (in terms of row size) are the tables in the database? If you use the CHECKSUM_AGG(BINARY_CHECKSUM(*)) method suggested by John, it will scan every row of the specified table. The NOLOCK hint helps, but on a large database, you are still hitting every row. You will also need to store the checksum for every row so that you tell one has changed.
Have you considered going at this from a different angle? If you do not want to modify the schema to add triggers, (which makes a sense, it's not your database), have you considered working with the application vendor that does make the database?
They could implement an API that provides a mechanism for notifying accessory apps that data has changed. It could be as simple as writing to a notification table that lists what table and which row were modified. That could be implemented through triggers or application code. From your side, ti wouldn't matter, your only concern would be scanning the notification table on a periodic basis. The performance hit on the database would be far less than scanning every row for changes.
The hard part would be convincing the application vendor to implement this feature. Since this can be handles entirely through SQL via triggers, you could do the bulk of the work for them by writing and testing the triggers and then bringing the code to the application vendor. By having the vendor support the triggers, it prevent the situation where your adding a trigger inadvertently replaces a trigger supplied by the vendor. |
C# is DateTime.Now the best way to measure a functions preformance? |
|c#|.net|datetime|timer| |
I need to find a bottleneck and need to accurately as possible measure time.
Is the following Code Snippet the best way to measure the performance?
DateTime startTime = DateTime.Now;
// Some Execution Process
DateTime endTime = DateTime.Now;
TimeSpan totalTimeTaken = endTime.Subtract(startTime);
|
|c#|.net|datetime|timer|performance| |
C# is DateTime.Now the best way to measure a function's preformance? |
Is DateTime.Now the best way to measure a function's performance? |
|c#|.net|performance|datetime|timer| |
HgTortoise in Vista 64-bit not showing the context menu |
|mercurial| |
I installed HgTortoise (Mercurial) in my Vista 64-bit and the context menu is not showing up when I right click a file or folder.
Is there any workaround for this problem? |
|mercurial|vista64| |
Implementing a '20 Questions'-like Wizard in a Database |
|sql|oracle-database|database-design| |
I am looking to implement a data-driven wizard with the question tree stored in an Oracle database. What is the best schema to use to make the database portion flexible (i.e. easy to add new paths of questions) without sacrificing too much in terms of performance? |
I think this is just another web browser. The most impact I expect to be improved Javascript performance, and the usability perspective. The first will benefit developers, especially when using Google Gears. I think the users will benefit the most from an enhanced user experience, the safety features, and ease of use.
I can only hope other browser vendors (MS) will follow Mozilla and Google to create a faster Javascript implementation, since this is the only thing that can truly impact web development. |
Yes, a GUID should always be unique. It is based on both hardware and time, plus a few extra bits to make sure it's unique. I'm sure it's theoretically possible to end up with two identical ones, but extremely unlikely in a real-world scenario.
Here's a great article by Raymond Chen on Guids:
[http://blogs.msdn.com/oldnewthing/archive/2008/06/27/8659071.aspx][1]
[1]: http://blogs.msdn.com/oldnewthing/archive/2008/06/27/8659071.aspx |
The simple answer is yes.
Raymond Chen wrote a [great article](http://blogs.msdn.com/oldnewthing/archive/2008/06/27/8659071.aspx) on GUIDs and why substrings of GUIDs are *not* guaranteed unique. The article goes in to some depth as to the way GUIDs are generated and the data they use to ensure uniqueness, which should go to some length in explaining *why* they are :-) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.