instruction
stringlengths
0
30k
What's the best (cross browser) way of restricting the maximum number of characters that can be entered into an html textarea?
You have two choices to do this. The Quick and Dirty is selecting your files (using ctrl) in Project Explorer view, right-click them, choose `Replace with...` and then you choose the best option for you, from `Latest from Repository`, or some `Branch` version. After getting those files you modify them (with a space, or fix something, your call and commit them to create a newer revision. A more clean way is choosing `Merge` at team menu and navigate through the wizard that will help you to recovery the old version in the actual revision. Both commands have their command-line equivalents: `svn revert` and `svn merge`.
How is [this][1] for starters. [1]: http://railsforum.com/viewtopic.php?id=17785 # The submit button in your child window's view: <%= button_to_function 'Save', "$('my_form').submit(); window.opener.location.reload(); window.close();" %>
I agree with the others -- set a default value of GetDate() on the LastUpdate column and then use a trigger to handle any updates. Just something simple like this: CREATE TRIGGER KeepUpdated on Profiles FOR UPDATE, INSERT AS UPDATE dbo.Profiles SET LastUpdate = GetDate() WHERE Username IN (SELECT Username FROM inserted) If you want to get really fancy, have it evaluate what's being changed versus what's in the database and only modify LastUpdate if there was a difference. Consider this... - **7am** - User 'jsmith' is created with a last name of 'Smithe' (oops), LastUpdate defaults to 7am - **8am** - 'jsmith' emails IT to say his name is incorrect. You immediately perform the update, so the last name is now 'Smith' and (thanks to the trigger) LastUpdate shows 8am - **2pm** - Your slacker coworker finally gets bored with StumbleUpon and checks his email. He sees the earlier message from 'jsmith' regarding the name change. He runs: *UPDATE Profiles SET LastName='Smith' WHERE Username='jsmith'* and then goes back to surfing MySpace. The trigger doesn't care that the last name was already 'Smith', however, so LastUpdate now shows 2pm. If you just blindly change LastUpdate whenever an update statement runs, it's TECHNICALLY correct because an update did happen, but it probably makes more sense to actually compare the changes and act accordingly. That way, the 2pm Update statement by the coworker would still run, but LastUpdate would still show 8am. --Kevin
I've tried JVoiceXML in the past and had some luck with it. [http://jvoicexml.sourceforge.net/][1] It's java of course, but that wasn't a problem for my situation. [1]: http://jvoicexml.sourceforge.net/
Are you using .Net 1.0 or 1.1? If so then catch(Exception ex) won't catch exceptions from unmanaged code. You'll need to use catch {} instead. See this article for further details: http://www.netfxharmonics.com/2005/10/net-20-trycatch-and-trycatchexception/
> "Also, you can put some code in to > catch all unhandled exceptions. Read > the link for more info, but the basics > are these two lines." This is false. This used to catch all unhandled exceptions in .NET 1.0/1.1 but it was a bug and it wasn't supposed to and it was fixed in .NET 2.0. AppDomain.CurrentDomain.UnhandledException Is only intended to be used as a last chance logging saloon so you can log the exception before the program exits. It wont catch the exception as of 2.0 onwards (although in .NET 2.0 at least there is a config value you can modify to make it act like 1.1 but it isn't recommended practice to use this.). Its worth noting that there are few exceptions that you _cannot_ catch, such as StackOverflowException and OutOfMemoryException. Otherwise as other people have suggested it might be an exception in a background thread somewhere. Also I'm pretty sure you can't catch unmanaged/native exceptions either.
As I mentioned [before](http://stackoverflow.com/questions/10961/have-you-used-a-wiki-in-your-project-or-group#10977), a Wiki is very unorganized. However, if that is the only argument from your developers, then invest some effort to create a simple index page and keep it updated (either do it yourself or ask people to link their contributions to the index). That way, the Wiki might grow into a very nice and quite comprehensive collection of documentation for all your work.
Find "sticky" items (sub-3 pg. docs / diagrams / etc) something that the team seems to be creating again and again & post it on the wiki. Make sure everyone has access to the wiki and knows its there - set up a notification mechanism if possible. With some luck, the next time they have to access, rather than dig it out of version control or their machines - they should hit the wiki. If they still don't, try to see if the team has enough slack to actually use the wiki - Subtler issues may lie beneath their reluctance.
You can't force developers to do something they do not have an incentive of using for; unfortunately wikis, like documentation (well, in fact wikis *are* documentation) rarely have any "cool" value for developers. Besides, they're already deep into dev work -- could you really bother them with a wiki? That being said, the people who pushed for the wiki (e.g., you) should be primarily responsible for updating it, and you really would have a lot of work cut out for you if you're serious about it. You might also try the ff: - It's not very structured you say -- a lot of people get turned off from ill-structured (hard-to-search/browse) wikis. So maybe you can fix that first - Maybe you can ask lead developers/project managers to populate it with things that are issues for them: things like code conventions and API design for your particular project - Lead by example: religiously document *your* part of the system. Setting a precedent may encourage others to do the same
ASP.NET AJAX allows you to register web services with the ScriptManager which will create JavaScript proxies for you to call. See <http://msdn.microsoft.com/en-us/library/bb515101.aspx>.
I have done some selling and even run some training sessions. I think some people are turned off by the lack of WYSIWYG editing and ability to paste formatted text from Word or Outlook. I know there are some tools to work around these, but they are still barriers. There are some areas where the wiki is being used to log certain areas, but people who update those are not doing anything else with it. I will use the wiki to document my specialised area regardless as it acts as a convenient brain extension. When starting a new development I use it as a notepad for ideas that I can expand on as it progresses. It would help if management would give it some vocal support, even if it is not made mandatory.
[SnippetsEmu][1] is a useful snippets plugin. [1]: http://slipperysnippets.blogspot.com/
We've been using a wiki in some form or another for a while now, but it does take a while for people to get on board. You might find that you will be the only one writing articles for some time, but bear with it, other people will come on board eventually. If someone sends an email around that contains information related to the project then helpfully point them in the direction of the wiki - and keep doing that - they should get the hint. We have a SharePoint portal and use the wiki from there - we customised it with our own branding so that it "looks the part" - I really feel this has helped to improve the uptake of it. Make sure that everyone is aware that the wiki is even more informal than email.... because there will be a "fear factor" that people may think anything they add to the wiki will be over-analysed.
You can use panels with automatic layout such as [FlowLayoutPanel][1] and [TableLayoutPanel][2]. Unfortunately there are only 2 panels with automatic layout out of box but you can create custom layout panel. [1]: http://msdn.microsoft.com/en-us/library/system.windows.forms.flowlayoutpanel.asp [2]: http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.aspx
You can use panels with automatic layout such as [FlowLayoutPanel][1] and [TableLayoutPanel][2]. Unfortunately there are only 2 panels with automatic layout out of box but you can create custom layout panel. I would recommend you to read following articles: [How to: Create a Resizable Windows Form for Data Entry][3] [Walkthrough: Creating a Resizable Windows Form for Data Entry][4] [1]: http://msdn.microsoft.com/en-us/library/system.windows.forms.flowlayoutpanel.asp [2]: http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.aspx [3]: http://msdn.microsoft.com/en-us/library/d4d31tbk.aspx [4]: http://msdn.microsoft.com/en-us/library/991eahec.aspx
You can use panels with automatic layout such as [FlowLayoutPanel][1] and [TableLayoutPanel][2]. Unfortunately there are only 2 panels with automatic layout out of box but you can create custom layout panel. I would recommend you to read following articles: [How to: Create a Resizable Windows Form for Data Entry][3] [Walkthrough: Creating a Resizable Windows Form for Data Entry][4] [1]: http://msdn.microsoft.com/en-us/library/system.windows.forms.flowlayoutpanel.asp [2]: http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.aspx [3]: http://msdn.microsoft.com/en-us/library/d4d31tbk.aspx [4]: http://msdn.microsoft.com/en-us/library/991eahec.aspx Another option would be using of WPF (Windows Presentation Presentation). WPF is a perfect match for your task. WPF controls can be hosted in WinForms apps so you don't have to switch to it completely.
How are partial methods used in C# 3.0?
|c#|partial-methods|
I have read about partial methods in the latest [C# language specification][1], so I understand the principles, but I'm wondering how people are actually using them. Is there a particular design pattern that benefits from partial methods? [1]: http://msdn.microsoft.com/en-us/vcsharp/aa336809.aspx
|c#|design-patterns|partial-methods|
|c#|design-patterns|.net-3.5|partial-methods|
The TEXTAREA tag does not have a MAXLENGTH attribute the way that an INPUT tag does, at least not in most standard browsers. A very simple and effective way to limit the number of characters that can be *typed* into a TEXTAREA tag is: <textarea onKeyPress="return ( this.value.length < 50 );"></textarea> This works because the boolean expression compares the field's length before the new character is added to the maximum length you want (50 in this example, use your own here), and returns true if there is room for one more, false if not. Returning false from most events cancels the default action. So if the current length is already 50 (or more), the handler returns false, the KeyPress action is cancelled, and the character is not added. One fly in the ointment is the possibility of pasting into a TEXTAREA, which does not cause the KeyPress event to fire, circumventing this check. Internet Explorer 5+ contains an onPaste event whose handler can contain the check. However, note that you must also take into account how many characters are waiting in the clipboard to know if the total is going to take you over the limit or not. Fortunately, IE also contains a clipboard object from the window object.[1] Thus: <textarea onKeyPress="return ( this.value.length < 50 );" onPaste="return (( this.value.length + window.clipboardData.getData('Text').length) < 50 );"></textarea> Again, the onPaste event and clipboardData object are IE 5+ only. For a cross-browser solution, you will just have to use an OnChange or OnBlur handler to check the length, and handle it however you want (truncate the value silently, notify the user, etc.). Unfortunately, this doesn't catch the error as it's happening, only when the user attempts to leave the field, which is not quite as friendly. [Source][1] Also, there is another way here, including a finished script you could include in your page: <http://cf-bill.blogspot.com/2005/05/textarea-maxlength-revisited.html> [1]: http://lists.evolt.org/archive/Week-of-Mon-20040315/156773.html
|c++|string|boolean|
Maybe this is a dumb question, but is there any way to convert a boolean value to a string such that 1 turns to "true" and 0 turns to "false"? I could just use an if statement, but it would be nice to know if there is a way to do that with the language or standard libraries. Plus, I'm a pedant. :)
Impersonation worked well for me in this scenario. We had a wizard that uploaded a zip file through the website, but we load balanced the site. Therefore needed to setup a way to save the file on all the machines. Let me know and I can answer further questions on getting it setup.
Impersonation worked well for me in this scenario. We had a wizard that uploaded a zip file through the website, but we load balanced the site. Therefore needed to setup a way to save the file on all the machines. There are many different ways to do it. We decided to make all requests to run under the user we setup and just added the web.config entry and setup the security permissions on the folders for the user. This [kb][1] article explains the setup very well. [1]: http://support.microsoft.com/kb/306158
Although that code looks quite secure, I've always held the opinion that any sufficiently motivated person could break it given adequate time. I do think it will take quite a bit of determination to get through that, but I'm relatively sure it could be done.
Disregarding the theoretical implications, it seems to be "Any language that has a keyword called 'class'" :-P
I agree that a macro might be the best fit. I just whipped up a test case (believe me I'm no good with C/C++ but this sounded fun): #include <stdio.h> #include <stdarg.h> #define BOOL_STR(b) (b?"true":"false") int main (int argc, char const *argv[]) { bool alpha = true; printf( BOOL_STR(alpha) ); return 0; }
The unix tool `xxd` is distributed as part of [`vim`](http://www.vim.org/download.php), and according to <http://www.vmunix.com/vim/util.html#xxd>, the source for xxd is <ftp://ftp.uni-erlangen.de:21/pub/utilities/etc/xxd-1.10.tar.gz>. It was written in C and is about 721 lines. The only licensing information given for it is this: * Distribute freely and credit me, * make money and share with me, * lose money and don't ask me. The unix tool `hexdump` is available from <http://gd.tuwien.ac.at/softeng/Aegis/hexdump.html>. It was written in C and can be compiled from source. It's quite a bit bigger than xxd, and is distributed under the GPL.
Try this Macro. Anywhere you want the "true" or false to show up just replace it with PRINTBOOL(var) where var is the bool you want the text for. #define PRINTBOOL(x) x?"true":"false"
To further what aib said, I would say that a language isn't really object oriented unless the standard libraries that are available are object oriented. The biggest example of this is PHP. Although it supports all the standard object oriented concepts, the fact that such a large percentage of the standard libraries aren't object oriented means that it's almost impossible to write your code in an object oriented way. It doesn't matter that they are introducing namespaces if all the standard libraries still require you to prefix all your function calls with stuff like mysql_ and pgsql_, when in a language that supported namespaces in the actual API, you could get rid of functions with mysql_ and have just a simple "include system.db.mysql.*" at the top of your file so that it would know where those things came from.
I think most of the answers so far are spot on - the more you plug away at it yourself, the larger the body of useful information will become, so slowly but surely people will naturally start to use it. The other approach you could use is this: Suggest that every time someone asks another team member a question about the project, they should answer the question as normal, but also add the answer to a section of the Wiki. This may take a few minutes extra, but it will mean that the next time someone asks the same question (which they inevitably will), you can save time by pointing them at the Wiki. This, in turn, should help people to start using the Wiki as a first source of information and help overall up-take.
In addition to @Fredrik's tip about setting project items to "Copy to Output Directory", you can also specify a post-build action in the project's properties in the Build tab and include CMD commands like copy.exe and move.exe.
If you open the .MSG file in a text editor, i believe you will find that the information you are after is stored as plain text inside the file. (It is on all the messages i have checked at least) It would be pretty easy to write some code to parse the file looking for lines beginning with "From:" or "To:" etc. and then extracting the information you need. If you need the body of the email as well, that may be a bit more complicated.
The convention I've most seen is simply camel case, like a method name... myLabel: but I've also seen labels prefixed with an underscore _myLabel: or with lab... labSomething: You can probably sense though from the other answers that you'll be hard-pushed to find a coding standard that says anything other than 'Don't use labels'. The answer then I guess is that you should use whatever style makes sense to you, as long as it's consistent.
What appears to be the matter with the code? OK, the question should be... what should the code do that it doesn't already. When I run the code, I see 2 red 'spikes' am I not ment to? You appear to draw the first spike within the clipped rectangle region verified by adding the the following code at the beginning of the onPaint function: `e.Graphics.FillRectangle( new SolidBrush( Color.Black ), b );` Then you perform a translation, reset the clip so at this point I assume the clientRectangle is being used as the appropriate clip region and then attempt to redarw the translated spike. Where's the bug?!?
What appears to be the matter with the code? OK, the question should be... what should the code do that it doesn't already. When I run the code, I see 2 red 'spikes' am I not ment to? You appear to draw the first spike within the clipped rectangle region verified by adding the the following after the declaration of teh Rectangle : `e.Graphics.FillRectangle( new SolidBrush( Color.Black ), b );` Then you perform a translation, reset the clip so at this point I assume the clientRectangle is being used as the appropriate clip region and then attempt to redarw the translated spike. Where's the bug?!?
I have a couple that I really like: [GlyFx][1] and [Liquidicity Vector Icons][2]. Those from Liquidicity are specially useful for WPF or Silverlight, you can make an interface that even zoomed looks great. [1]: http://glyfx.com/products/free.html [2]: http://www.gosquared.com/liquidicity/archives/122
You didn't mention for what OS, but the [WMI Redistributable Components version 1.0][1] definitely exist. [1]: http://www.microsoft.com/downloads/details.aspx?familyid=013BB284-3946-44A9-AC3C-BF2A569EAA72&displaylang=en "Microsoft Download Center"
You didn't mention for what OS, but the [WMI Redistributable Components version 1.0][1] definitely exists. [1]: http://www.microsoft.com/downloads/details.aspx?familyid=013BB284-3946-44A9-AC3C-BF2A569EAA72&displaylang=en "Microsoft Download Center"
You didn't mention for what OS, but the [WMI Redistributable Components version 1.0][1] definitely exists. For Windows Server 2003, the WMI SDK and redistributables are part of the [Server SDK][2] *I believe* that the same is true for the [Server 2008 SDK][3] [1]: http://www.microsoft.com/downloads/details.aspx?familyid=013BB284-3946-44A9-AC3C-BF2A569EAA72&displaylang=en "Microsoft Download Center" [2]: http://www.microsoft.com/downloads/details.aspx?FamilyId=484269E2-3B89-47E3-8EB7-1F2BE6D7123A&displaylang=en "Windows Server 2003 SDK Full Download" [3]: http://www.microsoft.com/downloads/details.aspx?FamilyId=F26B1AA4-741A-433A-9BE5-FA919850BDBF&displaylang=en "Microsoft Download Center"
I usually take that approach, but if I feel like it's going to cause confusion, I'll use ellipses like: `myFunction(...)` I guess if I were good, I would use those *any* time I was omitting parameters from a function in text.
Try this: var request = new XMLHttpRequest(); request.overrideMimeType( 'text/xml' ); request.onreadystatechange = process; request.open ( 'GET', url ); request.send( null ); function process() { if ( request.readyState == 4 && request.status == 200 ) { var xml = request.responseXML; } }
Try this: var request = new XMLHttpRequest(); request.overrideMimeType( 'text/xml' ); request.onreadystatechange = process; request.open ( 'GET', url ); request.send( null ); function process() { if ( request.readyState == 4 && request.status == 200 ) { var xml = request.responseXML; } } Notice the **overrideMimeType** and **responseXML**. <br> The readyState == 4 is 'completed'.
I recommend Git. If you're working by yourself SVN or CVS are hated by many people but they're solid options.
Version Control is essential to development, even if you're working by yourself because it protects you from yourself. If you make a mistake, it's a simple matter to rollback to a previous version of your code that you know works. This also frees you to explore and experiment with your code because you're free of having to worry about whether what you're doing is reversible or not. There are two major branches of Version Control Systems (VCS), Centralized and Distributed. Centralized VCS are based on using a central server, where everyone "checks out" a project, works on it, and "commits" their changes back to the server for anybody else to use. The major Centralized VCS are CVS and SVN. Both have been heavily criticized because "merging" "branches" is extremely painful with them. [TODO: write explanation on what branches are and why merging is hard with CVS & SVN] Distributed VCS let everyone have their own server, where you can "pull" changes from other people and "push" changes to a server. The most common Distributed VCS are Git and Mercurial. [TODO: write more on Distributed VCS] If you're working on a project I heavily recommend using a distributed VCS. I recommend Git because it's blazingly fast, but is has been criticized as being too hard to use. If you don't mind using a commercial product BitKeeper is supposedly easy to use.
> "Also, you can put some code in to > catch all unhandled exceptions. Read > the link for more info, but the basics > are these two lines." This is false. This used to catch all unhandled exceptions in .NET 1.0/1.1 but it was a bug and it wasn't supposed to and it was fixed in .NET 2.0. AppDomain.CurrentDomain.UnhandledException Is only intended to be used as a last chance logging saloon so you can log the exception before the program exits. It wont catch the exception as of 2.0 onwards (although in .NET 2.0 at least there is a config value you can modify to make it act like 1.1 but it isn't recommended practice to use this.). Its worth noting that there are few exceptions that you _cannot_ catch, such as StackOverflowException and OutOfMemoryException. Otherwise as other people have suggested it might be an exception in a background thread somewhere. Also I'm pretty sure you can't catch some/all unmanaged/native exceptions either.
I don't get it...your catch block just throws a new exception (with the same message). Meaning that your statement of: > The problem is that in some cases (not all) that my try/catch block won't catch it and instead stops execution as an unhandled exception. is exactly what is *expected* to happen.
@dmckee: I think the suggested solution is good, but for simple data (e.g. if only the name is needed) it could be augmented with auto-generated code. While there are lots of ways to auto-generate code, for something as simple as this I believe you could write a simple XSLT that takes in an XML representation of the enum and outputs the code file. The XML would be of the form: <EnumsDefinition> <Enum name="DogType"> <Value name="Vizsla" value="0" /> <Value name="Terrier" value="3" /> <Value name="YellowLab" value="10" /> </Enum> </EnumsDefinition> and the resulting code would be something similar to what dmckee suggested in his solution. For information of how to write such an XSLT try [here][1] or just search it up in google and find a tutorial that fits. Writing XSLT is not much fun IMO, but it's not that bad either, at least for relatively simple tasks such as these. [1]: http://www.w3schools.com/xsl/
I tried it and it looked promising at first but quickly had issues actually deploying it to a Medium Trust host.
PHP mail using Gmail
|php|email|gmail|
In my PHP webapp, I want to be notified via email whenever certain errors occur. I'd like to use my Gmail account for sending these. How could this be done?
> Are there any general advice or workarounds for organizing or redistributing templated member definitions across multiple files? Yes; don't. The C++ spec permits a compiler to be able to "see" the entire template (declaration _and_ definition) at the point of instantiation, and (due to the complexities of any implementation) most compilers retain this requirement. The upshot is that #inclusion of any template header must also #include any and all source required to instantiate the template. The easiest way to deal with this is to dump everything into the header, inline where posible, out-of-line where necessary. If you really regard this as an unacceptable affront, a common option is to split the template into the usual header/implementation pair, and then #include the implementation file at the end of the header. C++'s "export" feature may or may not provide another workaround. The feature is poorly supported and poorly defined; although it in principle should permit some kind of separate compilation of templates, it doesn't necessarily obviate the demand that the compiler be able to see the entire template body.
It's probably a bit late to be looking tonight at code trends for an interview tomorrow. Microsoft is currently busy doing what it has always done: me-too functionality, only better. New dynamically typed languages with a new language runtime and MVC are looking really promising. With WPF and Expression they're creating different interfaces for UI developers and business logic developers to use. I'm not sure about that - I'd rather see Expression Blend as part of VS. They're pushing open source more than they ever have - <http://www.codeplex.com> is getting busier. VS Express editions are an excellent route in to the technologies. With their Team System they're pushing Agile methods more and more - they've even resolved them with more structured processes like CMMI.
It's probably a bit late to be looking tonight at code trends for an interview tomorrow. Microsoft is currently busy doing what it has always done: me-too functionality, only better. New dynamically typed languages with a new language runtime and MVC are looking really promising. With WPF and Expression they're creating different interfaces for UI developers and business logic developers to use. I'm not sure about that - I'd rather see Expression Blend as part of VS. They're pushing open source more than they ever have - <http://www.codeplex.com> is getting busier. VS Express editions are an excellent route in to the technologies. With their Team System they're pushing Agile methods more and more - they've even resolved them with more structured processes like CMMI. ---------- -1? serves me right for starting with a sarcastic comment ;-( How about: <a href="http://lifehacker.com/398867/how-to-hack-a-technical-job-interview">how to hack an interview</a>?
In my biased opinion, C is the best point to start. The language is small, it's high level features are ubiquitous and the low level features let you learn the machine. I found the [C Primer Plus, 5th Edition][1] very helpful as a beginning programmer with almost no programming experience. It assumes no prior programming experience, fun to read and covers C in depth (including the latest C99 standard). [1]: http://www.amazon.com/Primer-Plus-5th-Stephen-Prata/dp/0672326973
insert/replace XML tag in XmlDocument
|java|xml|xquery|
I have a XmlDocument in java, created with the Weblogic XmlDocument parser. I want to replace the content of a tag in this xmldocument with my own data, or insert the tag if it isnt there. <customdata> <tag1 /> <tag2>mfkdslmlfkm</tag2> <location /> <tag3 /> </customdata> I for example want to insert some url in the location tag: <location>http://something</location> but otherwise leave the xml as is. Currently I use a xmlcursor: XmlObject xmlobj = XmlObject.Factory.parse(a.getCustomData(), options); XmlCursor xmlcur = xmlobj.newCursor(); while (xmlcur.hasNextToken()) { boolean found = false; if (xmlcur.isStart() && "schema-location".equals(xmlcur.getName().toString())) { xmlcur.setTextValue("http://replaced"); System.out.println("replaced"); found = true; } else if (xmlcur.isStart() && "customdata".equals(xmlcur.getName().toString())) { xmlcur.push(); } else if (xmlcur.isEnddoc()) { if (!found) { xmlcur.pop(); xmlcur.toEndToken(); xmlcur.insertElementWithText("schema-location", "http://inserted"); System.out.println("inserted"); } } xmlcur.toNextToken(); } I tried to find a "quick" xquery way to do this since the XmlDocument has an execQuery method, but didnt find it very easy. Do anyone have a better way than this? It seems a bit elaborate.
|regex|lisp|emacs|regular-expression|
|regex|emacs|lisp|
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? Edit: It looks like I *can* use macros to do what I want, I just have to think outside the box of isearch-forward-regex. I'll try what you suggested.
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 had the best answer so far -- not *exactly* what I was looking for but it worked for what I needed** --- @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? Edit: It looks like I *can* use macros to do what I want, I just have to think outside the box of isearch-forward-regex. I'll try what you suggested.
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 had the best answer so far -- not *exactly* what I was looking for but it worked for what I needed** Edit - this sort of worked, but after storing the macro, when I went back to use it later, I couldn't use it with C-xe. (ie, if I reboot emacs and then type M-x macro-name, and then C-xe, I get a message in the minibuffer like 'no last kbd macro' or something similar) --- @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? Edit: It looks like I *can* use macros to do what I want, I just have to think outside the box of isearch-forward-regex. I'll try what you suggested.
Have you tried reinstalling RubyGems? I had a pretty similar error message until I reuninstalled and for some reason, it installed into a different directory and then the problem went away.
I believe that physical security is more important for voting booth system rather than you know, code security. These machine by their very nature shouldn't be connected to any kind of public networks, especially not the the internet. But having a good physical security to prevent any sort of physical tempering is very important.
Just finally found [answer][1]... I was missing a gem, and thrown off by bad error message from Rails... [1]: http://www.shorepound.net/wpblog/?p=65
That's probably about the best you can do. Just be aware that anybody with enough dedication, can probably de-obfuscate your program. Just make sure you're comfortable with that before embarking on your project. I think the biggest problem with this would be to control who's using it on their site. If somebody goes to a site with your code on it, and likes what it does, it doesn't matter that they don't understand what the code does, or can't read it, when they can just copy the code, and use it on their own site.
A obfuscator won't help you at all if someone wants to figure out the code. The code still exists on the client machine and they can grab a copy of it and study it at their leisure. There is simply no way to hide code written in Javascript since the source code has to be handed to the browser for execution. If you want to hide your code, you have the following options: 1) Use an environment where compiled code (not source) is downloaded to the client, e.g. Flash or Silverlight. I'm not even sure that's foolproof, but it's certainly much better than Javascript. 2) Have a back end on the server side that does the work and a thin client that just makes requests to the server.
Brad Abrams' [Framework Design Guidelines][1] book is all about this. Might be worth a look. [1]: http://www.amazon.com/Framework-Design-Guidelines-Conventions-Development/dp/0321246756/
I'd say yes, it's enough if you also make sure than you compress the code as well using a tool like [Dean Edward's Packer][1] or similar. If you think about what is possible with tools like .NET Reflector in terms of reverse engineering compiled code / IL in .NET, you realize that there's nothing you can do to completely protect your investment. On the other hand, remember that folks who release their source code also seem to make do quite nicely anyway - it's their experience that people want more than their intellectual property. [1]: http://dean.edwards.name/packer/
You're always faced with the fact that any user that comes to your webpage will download some working version of your Javascript source. They _will_ have the source code. Obfuscating it may make it very difficult to be reused by someone with the intent to _steal_ your hard work. However, in many cases someone can even reuse the obfuscated source! Or in the worst case they can unravel it by hand and eventually comprehend it. An example of a situation like yours might be [Google Maps](http://maps.google.com/). The Javascript source is clearly obfuscated. However, for really private/sensitive logic they push the data to the server and have the server process that information using XMLHttpRequests (AJAX). With this design you have the important parts on the server side, much more tightly controlled.
If you want a Rails solution, **[Radiant CMS][1]** is a good option. It's simple, elegant, extensible and, of course, comes with all of the benefits of being based on Ruby on Rails. [1]: http://radiantcms.org/
Briefly: 1. Always use transactions 2. Don't use `Close()`, instead wrap your calls on an `ISession` inside a `using` statement From [the documentation](http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#manipulatingdata-flushing): > From time to time the `ISession` will execute the SQL statements needed to synchronize the ADO.NET connection's state with the state of objects held in memory. This process, flush, occurs by default at the following points > - from some invocations of `Find()` or `Enumerable()` > - from `NHibernate.ITransaction.Commit()` > - from `ISession.Flush()` > The SQL statements are issued in the following order > 1. all entity insertions, in the same order the corresponding objects were saved using `ISession.Save()` > 2. all entity updates > 3. all collection deletions > 4. all collection element deletions, updates and insertions > 5. all collection insertions > 6. all entity deletions, in the same order the corresponding objects were deleted using `ISession.Delete()` > (An exception is that objects using native ID generation are inserted when they are saved.) > **Except when you explicity `Flush()`, there are absolutely no guarantees about when the Session executes the ADO.NET calls, only the order in which they are executed**. However, NHibernate does guarantee that the `ISession.Find(..)` methods will never return stale data; nor will they return the wrong data. >It is possible to change the default behavior so that flush occurs less frequently. The `FlushMode` class defines three different modes: only flush at commit time (and only when the NHibernate `ITransaction` API is used), flush automatically using the explained routine, or never flush unless `Flush()` is called explicitly. The last mode is useful for long running units of work, where an `ISession` is kept open and disconnected for a long time. ... Also refer to [this section](http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#manipulatingdata-endingsession): > Ending a session involves four distinct phases: > - flush the session > - commit the transaction > - close the session > - handle exceptions > ## Flushing the Session ## > If you happen to be using the `ITransaction` API, you don't need to worry about this step. It will be performed implicitly when the transaction is committed. Otherwise you should call `ISession.Flush()` to ensure that all changes are synchronized with the database. > ## Committing the database transaction ## > If you are using the NHibernate ITransaction API, this looks like: > tx.Commit();` // flush the session and commit the transaction > If you are managing ADO.NET transactions yourself you should manually `Commit()` the ADO.NET transaction. > sess.Flush(); > currentTransaction.Commit(); > If you decide not to commit your changes: > tx.Rollback(); // rollback the transaction > or: > currentTransaction.Rollback(); > If you rollback the transaction you should immediately close and discard the current session to ensure that NHibernate's internal state is consistent. > ## Closing the ISession ## > A call to `ISession.Close()` marks the end of a session. The main implication of Close() is that the ADO.NET connection will be relinquished by the session. > tx.Commit(); > sess.Close(); > sess.Flush(); > currentTransaction.Commit(); > sess.Close(); > If you provided your own connection, `Close()` returns a reference to it, so you can manually close it or return it to the pool. Otherwise `Close()` returns it to the pool.
Gishu has the right idea : for( int idx = 0; idx < vectorLength; idx++) { if (!conditionAtVectorPosition( v, idx ) && checkedRow(v, idx)) setValueInVector( v, idx ); } private boolean checkedRow(Vector v, int idx) { for( rowIdx = 0; rowIdx < n; rowIdx++ ) { if( anotherConditionAtVector( v, rowIdx ) ) continue; if( conditionAtMatrixRowCol( m, rowIdx, idx ) ) return false; } return true; }
I'm not too sure to understand the first continue. I would copy Gishu and write something like ( sorry if there are some mistakes ) : for( int idx = 0; idx < vectorLength; idx++) { if( !conditionAtVectorPosition( v, idx ) && CheckedEntireMatrix(v)) setValueInVector( v, idx ); } inline bool CheckedEntireMatrix(Vector v) { for(rowIdx = 0; rowIdx < n; rowIdx++) if ( !anotherConditionAtVector(v,rowIdx) && conditionAtMatrixRowCol(m,rowIdx,idx) ) return false; return true; }
A simple linked list can be used for this. Basically you add new items to the end, and remove too old items from the start, it is a cheap data structure. example-code: list.push_end(new_data) while list.head.age >= age_limit: list.pop_head() If the list will be busy enough to warrant chopping off larger pieces than one at a time, then I agree with [dmo](http://stackoverflow.com/users/1807/dmo), use a tree structure or something similar that allows pruning on a higher level.
.Net drawing clipping bug
|winforms|system.drawing|gdi+|graphics|
gdi+ DrawLines function has a clipping bug that can be reproduced by running the following code: protected override void OnPaint(PaintEventArgs e) { PointF[] points = new PointF[] { new PointF(73.36f, 196), new PointF(75.44f, 32), new PointF(77.52f, 32), new PointF(79.6f, 196), new PointF(85.84f, 196) }; Rectangle b = new Rectangle(70, 32, 20, 164); e.Graphics.SetClip(b); e.Graphics.DrawLines(Pens.Red, points); // clipped incorrectly e.Graphics.TranslateTransform(80, 0); e.Graphics.ResetClip(); e.Graphics.DrawLines(Pens.Red, points); } Setting the antials mode on the graphics object resolves this but that is not a real solution. Does anybody know of an workaround?
|winforms|graphics|gdi+|system.drawing|
gdi+ DrawLines function has a clipping bug that can be reproduced by running the following c# code. When running the code two line paths appear that should be identical, because both of them are inside the clipping region, but when the clipping region is set one of the line segment is not drawn. protected override void OnPaint(PaintEventArgs e) { PointF[] points = new PointF[] { new PointF(73.36f, 196), new PointF(75.44f, 32), new PointF(77.52f, 32), new PointF(79.6f, 196), new PointF(85.84f, 196) }; Rectangle b = new Rectangle(70, 32, 20, 164); e.Graphics.SetClip(b); e.Graphics.DrawLines(Pens.Red, points); // clipped incorrectly e.Graphics.TranslateTransform(80, 0); e.Graphics.ResetClip(); e.Graphics.DrawLines(Pens.Red, points); } Setting the antials mode on the graphics object resolves this but that is not a real solution. Does anybody know of an workaround?
How do I close a popup window, and open the next page in the main window in ROR?
|ruby|ruby-on-rails|html|popup|
I have a popup window containing a form which gathers data for a report. When I click submit in that window, I want it to close the popup, and open the report in the original window that called the popup. I think I can open the report in the correct window by using { :target => <name of window> } in the form_tag, but I don't know how to determine or set the name of the originating window. I also don't know how to close the popup window.
|html|ruby|ruby-on-rails|
I agree with [Daniel Auger][1] and [kronoz][2] that this smells like an exception that has something to do with threads. Beyond that, here are my other questions: 1. What does the complete error message say? What kind of exception is it? 2. Based on the stack trace you've provided here, isn't the exception thrown by you code in TimeDefLexer.mTokens()? [1]: http://stackoverflow.com/users/1644/daniel-auger [2]: http://stackoverflow.com/users/3394/kronoz
You could use PEAR's mail function with Gmail's SMTP Server Note that when sending e-mail using Gmail's SMTP server, it will look like it came from your Gmail address, despite what you value is for $from. (following code taken from [About.com Programming Tips][1] ) <?php require_once "Mail.php"; $from = "Sandra Sender <sender@example.com>"; $to = "Ramona Recipient <recipient@example.com>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; // stick your GMAIL SMTP info here! ------------------------------ $host = "mail.example.com"; $username = "smtp_username"; $password = "smtp_password"; // -------------------------------------------------------------- $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> [1]: http://email.about.com/od/emailprogrammingtips/qt/et073006.htm
Other languages? Well, in Java you call e.printStackTrace(); It doesn't get much simpler than that.
It depends on what kind of sanitizing you are doing. For protecting against SQL injection, don't do anything to the data itself. Just use prepared statements, and that way, you don't have to worry about messing with the data that the user entered, and having it negatively affect your logic. You have to sanitize a little bit, to ensure that numbers are numbers, and dates are dates, since everything is a string as it comes from the request, but don't try to do any checking to do things like block keywords or anything. For protecting against XSS attacks, it would probably be easier to fix the data before it's stored. However, as others mentioned, sometimes it's nice to have a pristine copy of exactly what the user entered, because once you change it, it's lost forever. It's almost too bad there's not a fool proof way to ensure you application only puts out sanitized HTML the way you can ensure you don't get caught by SQL injection by using prepared queries.
Briefly: 1. Always use transactions 2. Don't use `Close()`, instead wrap your calls on an `ISession` inside a `using` statement From [the documentation](http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#manipulatingdata-flushing): > From time to time the `ISession` will execute the SQL statements needed to synchronize the ADO.NET connection's state with the state of objects held in memory. This process, flush, occurs by default at the following points > - from some invocations of `Find()` or `Enumerable()` > - from `NHibernate.ITransaction.Commit()` > - from `ISession.Flush()` > The SQL statements are issued in the following order > 1. all entity insertions, in the same order the corresponding objects were saved using `ISession.Save()` > 2. all entity updates > 3. all collection deletions > 4. all collection element deletions, updates and insertions > 5. all collection insertions > 6. all entity deletions, in the same order the corresponding objects were deleted using `ISession.Delete()` > (An exception is that objects using native ID generation are inserted when they are saved.) > **Except when you explicity `Flush()`, there are absolutely no guarantees about when the Session executes the ADO.NET calls, only the order in which they are executed**. However, NHibernate does guarantee that the `ISession.Find(..)` methods will never return stale data; nor will they return the wrong data. >It is possible to change the default behavior so that flush occurs less frequently. The `FlushMode` class defines three different modes: only flush at commit time (and only when the NHibernate `ITransaction` API is used), flush automatically using the explained routine, or never flush unless `Flush()` is called explicitly. The last mode is useful for long running units of work, where an `ISession` is kept open and disconnected for a long time. ... Also refer to [this section](http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#manipulatingdata-endingsession): > Ending a session involves four distinct phases: > - flush the session > - commit the transaction > - close the session > - handle exceptions > ## Flushing the Session ## > If you happen to be using the `ITransaction` API, you don't need to worry about this step. It will be performed implicitly when the transaction is committed. Otherwise you should call `ISession.Flush()` to ensure that all changes are synchronized with the database. > ## Committing the database transaction ## > If you are using the NHibernate ITransaction API, this looks like: > tx.Commit(); // flush the session and commit the transaction > If you are managing ADO.NET transactions yourself you should manually `Commit()` the ADO.NET transaction. > sess.Flush(); > currentTransaction.Commit(); > If you decide not to commit your changes: > tx.Rollback(); // rollback the transaction > or: > currentTransaction.Rollback(); > If you rollback the transaction you should immediately close and discard the current session to ensure that NHibernate's internal state is consistent. > ## Closing the ISession ## > A call to `ISession.Close()` marks the end of a session. The main implication of Close() is that the ADO.NET connection will be relinquished by the session. > tx.Commit(); > sess.Close(); > sess.Flush(); > currentTransaction.Commit(); > sess.Close(); > If you provided your own connection, `Close()` returns a reference to it, so you can manually close it or return it to the pool. Otherwise `Close()` returns it to the pool.
I like tools that will perform more than one task, Notepad++ is a great notepad replacement and has a Document Monitor plugin (installs with standard msi) that works great. It also is portable so you can have it on a thumb drive for use anywhere. For a command line option, PowerShell (which is really a new command line) has a great feature already mentioned. Get-Content someFile.txt -wait But you can also filter at the command line using a regular expression Get-Content web.log -wait | where { $_ -match "ERROR" }
A lot of the research on this is dedicated to detecting so-called "blue pill" attacks, that is, a malicious hypervisor that is actively attempting to evade detection. The classic trick to detect a VM is to populate the ITLB, run an instruction that **must** be virtualized (which necessarily clears out such processor state when it gives control to the hypervisor), then run some more code to detect if the ITLB is still populated. The first paper on it is located [here](http://www.symantec.com/avcenter/reference/Virtual_Machine_Threats.pdf), and a rather colorful explanation from a researcher's blog is located [here](http://www.matasano.com/log/930/side-channel-detection-attacks-against-unauthorized-hypervisors/). Bottom line from discussions on this is that there is always a way to detect a malicious hypervisor, and it's much simpler to detect one that isn't trying to hide.
Make a generic list of textboxes: List<TextBox> textBoxes = new List<TextBox>(); for (int i = 0; i < 10; i++) { TextBox textBox = new TextBox(); textBox.Text = "Textbox " + i; textBoxes.Add(textBoxes); } for (int i = 0; i < textBoxes.Count; i++) { textBoxes[i].Text = "New value " + i; // or like this TextBox textBox = textBoxes[i]; textBox.Text = "New val " + i; }
Make a generic list of textboxes: List<TextBox> textBoxes = new List<TextBox>(); // Create 10 textboxes in the collection for (int i = 0; i < 10; i++) { TextBox textBox = new TextBox(); textBox.Text = "Textbox " + i; textBoxes.Add(textBoxes); } // Loop through and set new values on textboxes i collection for (int i = 0; i < textBoxes.Count; i++) { textBoxes[i].Text = "New value " + i; // or like this TextBox textBox = textBoxes[i]; textBox.Text = "New val " + i; }
I always wrap a transaction in a using statement. using(IDbTransaction transaction ) { // logic goes here. transaction.Commit(); } Once the transaction moves out of scope, it is disposed. If the transaction is still active, it is rolled back. This behaviour fail-safes you from accidentally locking out the database. Even if an unhandled exception is thrown, the transaction will still roll-back. I've found this pattern has drastically reduced record locking issues.
I always wrap a transaction in a using statement. using(IDbTransaction transaction ) { // logic goes here. transaction.Commit(); } Once the transaction moves out of scope, it is disposed. If the transaction is still active, it is rolled back. This behaviour fail-safes you from accidentally locking out the database. Even if an unhandled exception is thrown, the transaction will still rollback. In my code I actually omit explicit rollbacks and rely on the using statement to do the work for me. I only explicitly perform commits. I've found this pattern has drastically reduced record locking issues.