instruction
stringlengths
0
30k
I need the name of the current logged in user in my Air/Flex application. The application will only be deployed on Windows machines. I think I could attain this by regexing the User directory, but am open to other ways.
Personally I think curses is overkill in this case. While the curses lib is nice (and I frequently use it myself) it's a PITA to relearn every time I haven't needed it for 12 months which has to be the sign of a bad interface design. If for some reason you can't get on with [the progress bar lib Joey suggested][1] roll your own and release it under a pretty free licence for instant kudos :) [1]: http://stackoverflow.com/questions/1306/#1318
Here is a solution that works in XP / Vista, but is definitely expandable to OSX, linux, I'd still be interested in another way. public static function GetCurrentOSUser():String{ // XP & Vista only. var userDirectory:String = File.userDirectory.resolvePath("").nativePath; var startIndex:Number = userDirectory.lastIndexOf("\\") + 1 var stopIndex:Number = userDirectory.length; var user = userDirectory.substring(startIndex, stopIndex); return user; }
Use [Robocopy][1], it has the ability to copy files in "restartable mode", plus it should respect the file attributes. And it comes with Vista and Server 2008, and you can download it for older OS's. Plus you can set it to retry on failed copies, to pick up files that are temporarily in use by another process. [1]: http://en.wikipedia.org/wiki/Robocopy
What are the current best options for parallelizing a CPU-intensive .NET app?
|.net|parallel-processing|
This is an open-ended question. What approaches should I consider?
Also I would try: File.userDirectory.name But I don't have Air installed so I can't really test this...
I don't disagree with Dan (although a better choice may just be not to answer)...but... Unit testing is the process of writing code to test the behavior and functionality of your system. Obviously tests improve the quality of your code, but that's just a superficial benefit of unit testing. The real benefit are to 1. Make it easier to change the technical implementation while making sure you don't change the behavior (refactoring). Properly unit tested code can be aggressively refactored/cleaned up with little chance of breaking anything. 2. Give developers confidence when adding behavior or making fixes. 3. Document your code 4. Indicate areas of your code that are tightly coupled. It's hard to unit test code that's tightly coupled 5. Provide a means to use your API and look for difficulties early on 6. Indicates methods and classes that aren't very cohesive You should unit test because its in your interest to deliver a maintainable and quality product to your client. I'd suggest you use it for any system, or part of a system, which models real-world behavior. In other words, it's particularly well suited for enterprise development. I would not use it for throw-away/utility programs. I would not use it for parts of a system that are problematic to test (UI is a common example, but that isn't always the case) The greatest pitfall is that developers test too large a unit, or they consider a method a unit. This is particularly true if you don't understand Inversion of Control - in which case your unit tests will always turn into end-to-end integration testing. Unit test should test individual behaviors - and most methods have many behaviors. The greatest misconception is that programmers shouldn't test. Only bad or lazy programmers believe that. Should the guy building your roof not test it? Should the doctor replacement a heart valve not test the new valve? Only a programmer can test that his code does what he intended it to do (QA can test edge cases - how code behaves when its told to do things the programmer didn't intend, and the client can do acceptance test - does the code do what what the client paid for it to do)
+1 for [Zen garden.][1] I like the resources at [inobscuro.com][2] [1]: http://www.csszengarden.com/ [2]: http://inobscuro.com/
As for Linux, I know that Pidgin has to determine idle time to change your status to away after a certain amount of time. You might open the source and see if you can find the code that does what you need it to do.
Check out this, I know it works in 2005 ([MSDN Doc](http://msdn.microsoft.com/en-us/library/ms174397.aspx)): Here is is for the pubs DB <pre><code> select * from pubs.sys.database_files </pre></code> Returns the size and max_size.
At my current job, my predecessor did not use any kind of version control. There are just mountains of folders in at least 3 different places where he kept all of his projects. Any random project folder can be expected to find at least one folder name "project (OLD)" and one named "project" With version control, you never have to make copies of "safe" builds. You don't really have to worry about your IDE corrupting the file you're working on (I'm looking at you, REALBasic 5.5) because is so easy to commit (Read: Save) your work every day. Needless to say, I installed version control the day after I found out it existed. Also, TortoiseSVN makes committing to the database as easy as right clicking a folder.
[The Open Design Community][1] is a great resource. [1]: http://www.opendesigns.org/
I second Luke's answer. I can Recommend [Confluence][1] and here is why: I tested extensively many commercial and free Wiki based solutions. Not a single one is a winner on all accounts, including confluence. Let me try to make your quest a little shorter by summarizing what I have learned to be a pain and what is important: * WYSIWYG is a most have feature for the Enterprise. A wiki without it, skip it * Saying that, in reality, WYSIWYG doesn't work perfectly. It is more of a feature you must have to get the casual users not be afraid of the monster, and start using it. But you and anyone that wants to seriously create content, will very quickly get used to the wiki markup. it is faster and more reliable. * You need good permissions controls (who can see, edit etc' a page). confluence has good, but I have my complaints (to complicated to be put here) * You will want a good *export* feature. Most will give you a single page "PDF" export, but you need much more. For example, lets say you have an FAQ, you want to export the entire FAQ right? will that work? * Macros: you want a community creating macros. (Macro is for example a report, embedding of external data etc) * Structure: you want to be able to say that a page is a child of a different page, and be able to browse the data. The wikipedia model, of orphaned pages with no sturcture will not work in the Enterprise. (think FAQ, you want to have a hierarchy no?) * Ability to *easily* attache picture to be embedded in the body of the page/article. In confluence, you need to upload the image and then can embed it, it could be a little better (CTR+V) but I guess this is easy enough for 80% of the users. At the end of the day, remember that a Wiki will be valuable to you the more flexible it is. It needs to be a "blank" canvas, and your imagination is then used to "build" the application. In Confluence, I found 3 different "best practices" on how to create a FAQ. That means I can implement MANY things. Some examples (I use my Wiki for) * FAQ: any error, problem is logged. Used by PS and ENG. reduced internal support time dramatically * Track account status: I implemetned sophisticated "dashboard" that you can see at a glance which customer is at what state, the software version they have, who in the company 'owns" the custoemr etc' * Product: all documentation, installation instructions, the "what's new" etc * Technical documentation, DB structure and what the tables mean * HR: contact list, Document repository good luck! [1]: http://www.atlassian.com/software/confluence/
The [plugin from Microsoft's Mikhail Arkhipov][1] does HTML and Comments, I don't believe it does C# strings, though. I use the [Agent Smith][2] plugin for [ReSharper][3] for that. [1]: http://blogs.msdn.com/mikhailarkhipov/archive/2007/12/31/spell-checker-update-2-1-a-few-bug-fixes-and-couple-of-new-features.aspx [2]: http://www.agentsmithplugin.com/ [3]: http://www.jetbrains.com/resharper/
You need to be using an uni-directional hash algorithm like SHA-1 suggested above with a salt. I would suggest this site for more information. It includes some sample code / implementation. http://www.obviex.com/samples/hash.aspx
OS X InputManager, anything similar on Windows
|windows|macos|apple|windows-api|
Is there anything similar on Windows what would achieve the same as the InputManager on OS X?
As mk says, SHA1 or MD5 are the standard ones, along with SHA2. What you want is more generally called a cryptographic hash function. Cryptographic hashes are designed to be one-way (given the resulting hash, you shouldn't be able to derive the original input). Also, the likelihood of two arbitrary strings having the same hash (known as a hash collision) should be low (ideally 1/number of hash values). Unfortunately, just because your passwords are hashed doesn't free you from having to try really hard to keep the hashed versions safe. Far too many people will use weak passwords that would be vulnerable to an off-line brute-force attack. Edit - several people have also already pointed out the importance of using a salt. A salt is a constant value that you mix in with the input before using the hash function. Having a unique salt prevents off-line attackers from using pre-computed tables of common passwords (rainbow tables) to brute-force your passwords even faster.
To clarify the answer, the solution was to open up the tcp ports from 1024-65535. The iptables looked liked this: <code> [root@MYSERVER ~]# service iptables status Table: filter Chain INPUT (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0 Chain FORWARD (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0 Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain RH-Firewall-1-INPUT (2 references) target prot opt source destination ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 255 ACCEPT esp -- 0.0.0.0/0 0.0.0.0/0 ACCEPT ah -- 0.0.0.0/0 0.0.0.0/0 ACCEPT udp -- 0.0.0.0/0 224.0.0.251 udp dpt:5353 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:631 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5801 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5802 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5804 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5901 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5902 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5904 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:9099 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:10000 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:1025 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited </code> I executed this command to add the new rule: <code> [root@MYSERVER ~]# iptables -I RH-Firewall-1-INPUT 14 -p tcp -m tcp --dport 1024:65535 -j ACCEPT </code> Then they looked like this: <code> [root@MYSERVER ~]# service iptables status Table: filter Chain INPUT (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0 Chain FORWARD (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0 Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain RH-Firewall-1-INPUT (2 references) target prot opt source destination ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 255 ACCEPT esp -- 0.0.0.0/0 0.0.0.0/0 ACCEPT ah -- 0.0.0.0/0 0.0.0.0/0 ACCEPT udp -- 0.0.0.0/0 224.0.0.251 udp dpt:5353 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:631 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5801 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5802 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5804 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpts:1025:65535 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5901 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5902 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5904 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:9099 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:10000 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:1025 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited </code> Save the iptables when you've verified that it works: <code> [root@MYSERVER ~]# service iptables save </code>
Is just not accepting any connections on port 80 an option? I'm a complete web server noob so I don't know if the server can operate without an unsecured listen port but if the server can operate only listen on port 443 that would seem to be simplest option. Another option would be a redirect from the unsecure port to the secure one
Try using the [UIElement.SnapsToDevicePixels][1] property on the UI elements of your window. People tend to report it works best for [graphics and lines][2], but I've noticed improvment in text rendering with it as well. [1]: http://msdn.microsoft.com/en-us/library/system.windows.uielement.snapstodevicepixels.aspx [2]: http://blogs.msdn.com/seema/archive/2006/10/31/on-some-monitors-it-seems-that-thin-wpf-lines-are-blurred-across-two-pixels-instead-of-one-ick-how-do-i-get-sharply-rendered-lines.aspx
InputManagers are still available on Leopard, *except*: - they need to be in the Local domain (`/Library/InputManagers`); you cannot install them per-user any more, - they need to have appropriate privileges, - in 64-bit, they won't get loaded at all. [The Leopard AppKit Release Notes have more specific details.][1] [1]: http://developer.apple.com/releasenotes/Cocoa/AppKit.html#NSInputManager
Here is one that does the rotation in place instead of using a completely new array to hold the result. I've left off initialization of the array and printing it out. This only works for square arrays but they can be of any size. Memory overhead is equal to the size of one element of the array so you can do the rotation of as large an array as you want. (code is C++) int a[4][4]; int n=4; int tmp; for (int i=0; i<n/2; i++){ for (int j=i; j<-i-1; j++){ tmp=a[i][j]; a[i][j]=a[j][n-i-1]; a[j][n-i-1]=a[n-i-1][n-j-1]; a[n-i-1][n-j-1]=a[n-j-1][i]; a[n-j-1][i]=tmp; } }
Order an Array like another Array in C#
|c#|array|
I'm looking for the best algorithm to take array A {0,1,2,3} and make order it like array B {3,1,0,2}. Any ideas?
|c#|arrays|
It's pretty tricky and interesting. I'm sure I have the details wrong, but the overview is this: The program's can already talk to each other through Joel's server, so they can exchange information with each other and Joel's server. Further, Joel has their external IP addresses, and they give joel information about their internal IP addresses. They decide to try this hole punch technique. Computer A initiate a TCP connection with Computer B using B's external IP address. It won't go through, but what it does is tell's A's router that it needs to allow incoming packets from B on a given port. Computer B does the same thing, but its message gets through to A since A's router opened a port/ip combination that matches what B sent (there's some port magic that happens here - this is non trivial, but doable). B's router remembers that B initiated a connection with A on a given port and IP, and so A's packets now flow into B past their router correctly as well. So it's actually pretty straight forward, but the implementation has details, especially regarding how ports are given to new TCP connections, and how NAT routers *typically* deal with TCP requests and how they map to external ports. These details are the interesting , and difficult, bit. -Adam
It's pretty tricky and interesting. I'm sure I have some details wrong, but the overview is this: The programs can already talk to each other through Joel's server, so they can exchange information with each other and Joel's server. Further, Joel has their external IP addresses, and they give joel information about their internal IP addresses. They decide to try this hole punch technique. Computer A initiates a TCP connection with Computer B using B's external IP address. It won't go through, but what it does is tell's A's router that it needs to allow incoming packets from B on a given port. Computer B does the same thing, but its message gets through to A since A's router opened a port/ip combination that matches what B sent (there's some port magic that happens here - this is non trivial, but doable). B's router remembers that B initiated a connection with A on a given port and IP, and so A's packets now flow into B past their router correctly as well. So it's actually pretty straight forward, but the implementation has details, especially regarding how ports are given to new TCP connections, and how NAT routers *typically* deal with TCP requests and how they map to external ports. These details are the interesting, and difficult, bit. -Adam
There are some parallel extensions to .NET that are currently in testing and available at Microsoft's [Parallel Computing Developer Center][1]. They have a few interesting items that you would expect like Parallel foreach and a parallel version of LINQ called PLINQ. Some of the best information about the extensions is on [Channel 9][2]. [1]: http://msdn.microsoft.com/en-us/concurrency/default.aspx [2]: http://channel9.msdn.com/tags/Parallel+Extensions/
Unit testing is, roughly speaking, testing bits of your code in isolation with test code. The immediate advantages that come to mind are: - Running the tests becomes automate-able and repeatable - You can test at a much more granular level than point-and-click testing via a GUI Note that if your test code writes to a file, opens a database connection or does something over the network, it's more appropriately categorized as an integration test. Integration tests are a good thing, but should not be confused with unit tests. Unit test code should be short, sweet and quick to execute. Another way to look at unit testing is that you write the tests first. This is known as Test-Driven Development (TDD for short). TDD brings additional advantages: - You don't write speculative "I might need this in the future" code -- just enough to make the tests pass - The code you've written is always covered by tests - By writing the test first, you're forced into thinking about how you want to call the code, which usually improves the design of the code in the long run. If you're not doing unit testing now, I recommend you get started on it. Get a good book, practically any xUnit-book will do because the concepts are very much transferable between them. Sometimes writing unit tests can be painful. When it gets that way, try to find someone to help you, and resist the temptation to "just write the damn code". Unit testing is a lot like washing the dishes. It's not always pleasant, but it keeps your metaphorical kitchen clean, and you really want it to be clean. :)
Unit testing is, roughly speaking, testing bits of your code in isolation with test code. The immediate advantages that come to mind are: - Running the tests becomes automate-able and repeatable - You can test at a much more granular level than point-and-click testing via a GUI Note that if your test code writes to a file, opens a database connection or does something over the network, it's more appropriately categorized as an integration test. Integration tests are a good thing, but should not be confused with unit tests. Unit test code should be short, sweet and quick to execute. Another way to look at unit testing is that you write the tests first. This is known as Test-Driven Development (TDD for short). TDD brings additional advantages: - You don't write speculative "I might need this in the future" code -- just enough to make the tests pass - The code you've written is always covered by tests - By writing the test first, you're forced into thinking about how you want to call the code, which usually improves the design of the code in the long run. If you're not doing unit testing now, I recommend you get started on it. Get a good book, practically any xUnit-book will do because the concepts are very much transferable between them. Sometimes writing unit tests can be painful. When it gets that way, try to find someone to help you, and resist the temptation to "just write the damn code". Unit testing is a lot like washing the dishes. It's not always pleasant, but it keeps your metaphorical kitchen clean, and you really want it to be clean. :) ---------- Edit: One misconception comes to mind, although I'm not sure if it's so common. I've heard a project manager say that unit tests made the team write all the code twice. If it looks and feels that way, well, [you're doing it wrong][1]. Not only does writing the tests usually speed up development, but it also gives you a convenient "now I'm done" indicator that you wouldn't have otherwise. [1]: http://icanhascheezburger.com/2007/04/28/youre-doing-it-wrong-2/
Have a look at #ziplib (www.icsharpcode.com). It's GPL, but you can use it in closed-source, commercial applications. They don't say anything specifically on their page about using it with the Compact Framework, so you'd have to give it a test yourself (that said, it's pure C# without any external dependencies, so the chances are somewhat good that it will work).
Something I didn't see mentioned is [PCMag Radio][1]. That's a more consumer tech-oriented show, but they do geek out fairly often, and the chatter is always interesting. [1]: http://www.pcmag.com/category2/0,2806,2007098,00.asp
If you need your linebreaks preserved, use a CDATA block, as [tweakt said](http://stackoverflow.com/questions/7277/is-it-bad-practice-to-be-sensitive-to-linebreaks-in-xml-documents#7280) Otherwise beware. Most of the time, the linebreaks will be preserved by XML software, but sometimes they won't, and you really don't want to be relying on things which only work by coincidence
What about using attributes to store the data, rather than text nodes: <Address Street="15 Sample St" City="Example Bay" State="" Country="Some Country"/> I know the use of attributes vs. text nodes is an often debated subject, but I've stuck with attributes 95% of the time, and haven't had any troubles because of it.
PDF Editing in PHP?
|php|pdf|
Does anyone know of a good method for editing PDFs in PHP? Preferably open-source/zero-license cost methods. :) I am thinking along the lines of opening a PDF file, replacing text in the PDF and then writing out the modified version of the PDF? I have programmatically created PDF files in the past using FPDF, but found it a little unwieldy at times.
Visual Studio - new "default" property values for inherited controls
|c#|.net|visual-studio|vb.net|
I'm looking for help setting a new default property value for an inherited control in Visual Studio: class NewCombo : System.Windows.Forms.ComboBox { public NewCombo() { DropDownItems = 50; } } The problem is that the base class property "DropDownItems" has a 'default' attribute set on it that is a different value (not 50). As a result, when I drag the control onto a form, the designer file gets an explicit 'mycontrol.DropDownItems = 50;' line. At first this doesn't matter. But if later I change my inherited class to 'DropDownItems = 45;' in the constructor this does not affect any of the controls on any form since all those designer files still have the value 50 hardcoded in them. And the whole point was to have the value set in one place so I can deal with the customer changing his mind. Obviously, if I were creating my own custom property in the subclass, I could give it its own designer default attribute of whatever I wanted. But here I'm wanting to change the default values of properties in the base. Is there any way to apply Visual Studio attributes to a base class member? Or is there some other workaround to get the result I want? Thanks for any help
We use [pdflib](http://www.pdflib.com/pdflib-gmbh/) to create PDF files from our rails apps. It has bindings for PHP, and a ton of other languages. We use the commmercial version, but they also have a [free/open source version](http://www.pdflib.com/download/pdflib-family/pdflib-lite/) which has some limitations. Unfortunately, this only allows creation of PDF's. If you want to open and 'edit' existing files, pdflib do provide [a product which does this this](http://www.pdflib.com/products/pdflib-family/pdi/), but costs a [LOT](http://www.pdflib.com/products/pdflib-family/prices-licensing/)
TortoiseSVN works great. You don't even need a Subversion server, you can create a local repository through the tool. Since it integrates right into Windows Explorer, it makes it easy to work with in a variety of scenarios. You also then have the option to work with remote Subversion servers or Team Foundation Servers (via [SVNBridge][1]). [1]: http://www.codeplex.com/SvnBridge
You can use [assembla.com][1] to host your project. They offer subversion, git and mercurial hosting. I personally use their subversion hosting for a free and private one-man project. As an added bonus, you also get a wiki and a ticketing system. Which can help you manage your stuff. And the best thing is that you don't have to setup your subversion server and it is hosted off-site. It's really good for a free service. Personnaly, i use [TortoiseSVN][2] as my client but it isn't integrated in visual studio. For the integration, you can try [VisualSVN][3] (not free) or [AnkhSVN][4] (free) [1]: http://www.assembla.com/tour [2]: http://tortoisesvn.tigris.org/ [3]: http://www.visualsvn.com/visualsvn/ [4]: http://ankhsvn.open.collab.net/
I prefer distributed version control for personal projects, because they eliminate the need for a server. **Mercurial** is the one I try to use most of the time, but I've been hearing good things about **git** as well.
[Git][1] is very lightweight and is just as suitable for personal projects as it is for huge projects like the Linux kernel. There is lots of tutorial documentation available on its web site that will get you started. Example: git init git add . git commit -m "my first commit!" [1]: http://git.or.cz
[Git][1] is very lightweight and is just as suitable for personal projects as it is for huge projects like the Linux kernel. There is lots of tutorial documentation available on its web site that will get you started. Example: git init git add . git commit -m "my first commit!" If you are keen on Visual Studio integration, I would probably recommend Subversion, as there are a number of plugins that may make your life easier. Also, TortoiseSVN is definitely worth installing. [1]: http://git.or.cz
Choosing a multiplier for a (string) hash function
|performance|algorithm|
Do you have any advice/rules on selecting a multiplier to use in a (multiplicative) hash function. The function is computing the hash value of a string.
I use [Perforce][1] at work and at home for hobby projects. It is easy enough to set up, and allows two users and five workspaces without having to pay for a license. Also has a Visual Studio integration plugin. [1]: http://www.perforce.com
If you are using a framework like [django][1], the framework can easily do this for you using standard filters. In fact, I'm pretty sure django automatically does it unless you tell it not to. Otherwise, I would recommend using some sort of regex validation before accepting inputs from forms. I don't think there's a silver bullet for your problem, but using the re module, you should be able to construct what you need. [1]: http://www.djangoproject.com/
ASP .Net Custom Client-Side Validation
|asp.net|javascript|validation|
I have a custom validation function in JavaScript in a user control on a .Net 2.0 web site which checks to see that the fee paid is not in excess of the fee amount due. I've placed the validator code in the ascx file, and I have also tried using Page.ClientScript.RegisterClientScriptBlock() and in both cases the validation fires, but cannot find the JavaScript function. The output in Firefox's error console is "feeAmountCheck is not defined". Here is the function (this was taken directly from firefox->view source) <script type="text/javascript"> function feeAmountCheck(source, arguments) { var amountDue = document.getElementById('ctl00_footerContentHolder_Fees1_FeeDue'); var amountPaid = document.getElementById('ctl00_footerContentHolder_Fees1_FeePaid'); if (amountDue.value > 0 && amountDue >= amountPaid) { arguments.IsValid = true; } else { arguments.IsValid = false; } return arguments; } </script> Any ideas as to why the function isn't being found? How can I remedy this without having to add the function to my master page or consuming page? Thanks in advance.
If you're using .Net 2.0 and Ajax - you should use: ScriptManager.RegisterClientScriptBlock It will work better in Ajax environments then the old Page.ClientScript version.
You can relocate it by editing the **DocumentRoot** setting in XAMPP\apache\conf\httpd.conf. It should currently be: > C:/xampp/htdocs Change it to: > C:/projects/transitCalculator/trunk
I would look into IMAP http://us3.php.net/imap
How can I get the authenticated user name under Apache using plain HTTP authentication and PHP?
|php|apache|authentication|
First, let's get the security considerations out of the way. I'm using simple authentication under Apache for a one-off, internal use only, non-internet connected lan, php web app. How can get I the HTTP authenticated user name in PHP?
Try changing the argument names to "sender" and "args". And, after you have it working, switch the call over to ScriptManager.RegisterClientScriptBlock, regardless of AJAX use.
I'm sure you could write a small app that takes an XSD file and parses it into a SQL script. I've never seen code out there to do it though, but that's not saying it doesn't exist.
You can set Apache to serve pages from anywhere with any restrictions but it's normally distributed in a more secure form. Editing your apache files (http.conf is one of the more common names) will allow you to set any folder so it appears in your webroot.
You can set Apache to serve pages from anywhere with any restrictions but it's normally distributed in a more secure form. Editing your apache files (http.conf is one of the more common names) will allow you to set any folder so it appears in your webroot. EDIT: alias myapp c:\myapp\ I've edited my answer to include the format for creating an alias in the http.conf file which is sort of like a shortcut in windows or a symlink under un*x where Apache 'pretends' a folder is in the webroot. This is probably going to be more useful to you in the long term.
I second Luke's answer. I can Recommend [Confluence][1] and here is why: I tested extensively many commercial and free Wiki based solutions. Not a single one is a winner on all accounts, including confluence. Let me try to make your quest a little shorter by summarizing what I have learned to be a pain and what is important: * WYSIWYG is a most have feature for the Enterprise. A wiki without it, skip it * Saying that, in reality, WYSIWYG doesn't work perfectly. It is more of a feature you must have to get the casual users not be afraid of the monster, and start using it. But you and anyone that wants to seriously create content, will very quickly get used to the wiki markup. it is faster and more reliable. * You need good permissions controls (who can see, edit etc' a page). confluence has good, but I have my complaints (to complicated to be put here) * You will want a good *export* feature. Most will give you a single page "PDF" export, but you need much more. For example, lets say you have an FAQ, you want to export the entire FAQ right? will that work? * Macros: you want a community creating macros. You asked for example about the ability to **rate** pages, here is a [link][2] to a Macro for Confluence that lets you do that * Structure: you want to be able to say that a page is a child of a different page, and be able to browse the data. The wikipedia model, of orphaned pages with no sturcture will not work in the Enterprise. (think FAQ, you want to have a hierarchy no?) * Ability to *easily* attache picture to be embedded in the body of the page/article. In confluence, you need to upload the image and then can embed it, it could be a little better (CTR+V) but I guess this is easy enough for 80% of the users. At the end of the day, remember that a Wiki will be valuable to you the more flexible it is. It needs to be a "blank" canvas, and your imagination is then used to "build" the application. In Confluence, I found 3 different "best practices" on how to create a FAQ. That means I can implement MANY things. Some examples (I use my Wiki for) * FAQ: any error, problem is logged. Used by PS and ENG. reduced internal support time dramatically * Track account status: I implemetned sophisticated "dashboard" that you can see at a glance which customer is at what state, the software version they have, who in the company 'owns" the custoemr etc' * Product: all documentation, installation instructions, the "what's new" etc * Technical documentation, DB structure and what the tables mean * HR: contact list, Document repository good luck! [1]: http://www.atlassian.com/software/confluence/ [2]: http://confluence.atlassian.com/display/CONFEXT/Rate+Macro
I second Luke's answer. I can Recommend [Confluence][1] and here is why: I tested extensively many commercial and free Wiki based solutions. Not a single one is a winner on all accounts, including confluence. Let me try to make your quest a little shorter by summarizing what I have learned to be a pain and what is important: * WYSIWYG is a most have feature for the Enterprise. A wiki without it, skip it * Saying that, in reality, WYSIWYG doesn't work perfectly. It is more of a feature you must have to get the casual users not be afraid of the monster, and start using it. But you and anyone that wants to seriously create content, will very quickly get used to the wiki markup. it is faster and more reliable. * You need good permissions controls (who can see, edit etc' a page). confluence has good, but I have my complaints (to complicated to be put here) * You will want a good *export* feature. Most will give you a single page "PDF" export, but you need much more. For example, lets say you have an FAQ, you want to export the entire FAQ right? will that work? * Macros: you want a community creating macros. You asked for example about the ability to **rate** pages, here is a [link][2] to a Macro for Confluence that lets you do that * Structure: you want to be able to say that a page is a child of a different page, and be able to browse the data. The wikipedia model, of orphaned pages with no sturcture will not work in the Enterprise. (think FAQ, you want to have a hierarchy no?) * Ability to *easily* attache picture to be embedded in the body of the page/article. In confluence, you need to upload the image and then can embed it, it could be a little better (CTR+V) but I guess this is easy enough for 80% of the users. At the end of the day, remember that a Wiki will be valuable to you the more flexible it is. It needs to be a "blank" canvas, and your imagination is then used to "build" the application. In Confluence, I found 3 different "best practices" on how to create a FAQ. That means I can implement MANY things. Some examples (I use my Wiki for) * FAQ: any error, problem is logged. Used by PS and ENG. reduced internal support time dramatically * Track account status: I implemetned sophisticated "dashboard" that you can see at a glance which customer is at what state, the software version they have, who in the company 'owns" the custoemr etc' * Product: all documentation, installation instructions, the "what's new" etc * Technical documentation, DB structure and what the tables mean * HR: contact list, Document repository My runner up (15 month ago) was free [Deki_Wiki][3], time has passed, so I don't know if this would be still my runner up. good luck! [1]: http://www.atlassian.com/software/confluence/ [2]: http://confluence.atlassian.com/display/CONFEXT/Rate+Macro [3]: http://wiki.developer.mindtouch.com/Deki_Wiki
I've used InnoSetup several years ago, before Vista, and was very happy with it then. I only had a few files to install and a Start menu icon. It worked great, and was easy to learn.
Ensure that you're modifying the modelview matrix by putting the following before the glRotatef call: glMatrixMode(GL_MODELVIEW); Otherwise, you may be modifying either the projection or a texture matrix instead.
Do you get a 1 unit straight line? It seems that 90deg rot. around Y is going to have you looking at the side of a triangle with no depth. You should try rotating around the Z axis instead and see if you get something that makes more sense. OpenGL has two matrices related to the display of geometry, the ModelView and the Projection. Both are applied to coordinates before the data becomes visible on the screen. First the ModelView matrix is applied, transforming the data from model space into view space. Then the Projection matrix is applied with transforms the data from view space for "projection" on your 2D monitor. ModelView is used to position multiple objects to their locations in the "world", Projection is used to position the objects onto the screen. Your code seems fine, so I assume from reading the documentation you know what the nature of functions like glPushMatrix() is. If rotating around Z still doesn't make sense, verify that you're editing the ModelView matrix by calling glMatrixMode.
The latest version of .Net 3.5 SP1 now allows you to run managed executables over a network share without using CasPol. See this [post][1] [1]: http://blogs.msdn.com/brada/archive/2008/08/13/net-framework-3-5-sp1-allows-managed-code-to-be-launched-from-a-network-share.aspx
Update: I found a much more elegant solution: class MyCompositeObject { DateTime CreatedDate; string SomeAttribute; Object Obj1; { class MyCompositeObjects : List<MyCompositeObject> { } I found that due to reflection, the specific type stored in Obj1 is resolved at runtime and the type specific DataTemplate is applied as expected!
#Perl 6:Procedural# sub factorial ( int $n ){ my $result = 1; loop ( ; $n > 0; $n-- ){ $result *= $n; } return $result; }
C: Edit: Actually C++ I guess, because of the variable declaration in the for loop. int factorial(int x) { int product = 1; for (int i = x; i > 0; i--) { product *= i; } return product; }
OpenGL Rotation
|opengl|c++|
I'm trying to do a simple rotation in OpenGL but must be missing the point. I'm not looking for a specific fix so much as a quick explanation or link that explains OpenGL rotation more generally. At the moment I have code like this: glPushMatrix(); glRotatef(90.0, 0.0, 1.0, 0.0); glBegin(GL_TRIANGLES); glVertex3f( 1.0, 1.0, 0.0 ); glVertex3f( 3.0, 2.0, 0.0 ); glVertex3f( 3.0, 1.0, 0.0 ); glEnd(); glPopMatrix(); But the result is not a triangle rotated 90 degrees.
It sounds to me that you'll want to handle two events: OnFocus: Will trigger when the textbox gains focus. You can store the initial value of the box. OnBlur: Will trigger when the textbox loses focus. At this point you can do your validation and decide if you want to roll back or not.
It sounds to me that you'll want to handle two events: GotFocus: Will trigger when the textbox gains focus. You can store the initial value of the box. LostFocus: Will trigger when the textbox loses focus. At this point you can do your validation and decide if you want to roll back or not.
I always hate to answer "don't", but you'd be better off indexing with something like Lucene ([PyLucene][1]). That and storing the paths in the database rather than the file contents is almost always recommended. To add to that, none of those database engines will store LOBs in a separate dataspace (they'll be embedded in the table's data space) so any of those engines should perfom nearly equally as well (well except sqllite). You need to move to Informix, DB2, SQLServer or others to get that kind of binary object handling. [1]: http://pylucene.osafoundation.org/
Dependency injection is what you're looking for. Rather than have those functions go out and look for their dependencies, inject the dependencies into the functions. That is, when you call the functions pass the data they want to them. That way it's easy to put a testing framework around a class because you can simply inject mock objects where appropriate. It's hard to avoid some global state, but the best way to do this is to use factory classes at the highest level of your application, and everything below that very top level is based on dependency injection. Two main benefits: one, testing is a heck of a lot easier, and two, your application is much more loosely coupled. You rely on being able to program against the interface of a class rather than its implementation.
Go to the table row's BackgroundColor property and choose "Expression..." Use this expression: =IIf(RowNumber(Nothing) Mod 2 = 0, "Silver", "Transparent") This trick can be applied to many areas of the report. Not looking for rep--I just researched this question myself and thought I'd share.
Why store the files in the database at all? Simply store your meta-data and a filename. If you need to copy them to a new location for some reason, just do that as a file system copy. Once you remove the file contents then any competent database will be able to handle the meta-data for a few hundred thousand files.
Here's one way to do it: import inspect def get_subclasses(mod, cls): """Yield the classes in module ``mod`` that inherit from ``cls``""" for name, obj in inspect.getmembers(mod): if hasattr(obj, "__bases__") and cls in obj.__bases__: yield obj
There is possible merit in testing private methods of a class, particularly with <a href="http://en.wikipedia.org/wiki/Test-driven_development">test driven development</a>, where you would like to design small tests before you write any code. Creating a test with access to private members and methods can test areas of code which are difficult to target specifically with access only to public methods. If a public method has several steps involved, it can consist of several private methods, which can then be tested individually. Advantages: - can test to a finer granularity Disadvantages: - test code must reside in the same file as source code, which can be more difficult to maintain - similarly with .class output files, they must remain within the same package as declared in source code However, if continuous testing requires this method, it may be a signal that the private methods should be extracted, which could be tested in the traditional, public way. Here is a convoluted example of how this would work: // import statements and package declarations public class ClassToTest { private int decrement(int toDecrement) { toDecrement--; return toDecrement; } // constructor and rest of class public static class StaticInnerTest extends TestCase { public StaticInnerTest(){ super(); } public void testDecrement(){ int number = 10; ClassToTest toTest= new ClassToTest(); int decremented = toTest.decrement(number); assertEquals(9, decremented); } public static void main(String[] args) { junit.textui.TestRunner.run(StaticInnerTest.class); } } } Inner class would be compiled to `ClassToTest$StaticInnerTest`. See also: http://www.javaworld.com/javaworld/javatips/jw-javatip106.html
I think the SCM policies and procedures a team adopts are going to be very dependent on the development process they are using. If you've got a team of 50 with several people working on major changes simultaneously and releases only occurring every 6 months, it makes a lot of sense for everyone to have his own branch where he can work in isolation and only merge in changes from other people when he wants them. On the other hand, if you're a team of 5 all sitting in the same room it makes sense to branch much less frequently. Assuming you're working on a small team where communication and collaboration is good and releases are frequent, it makes very little sense to ever branch IMO. On one project we simply rolled the SVN revision number into the product version number for all our releases and we never even tagged. In the rare event that there was a critical bug found in prod we would simply branch straight from the revision that was released. But most of the time we simply fixed the bug in the branch and released from trunk at the end of the week as scheduled. If your releases are frequent enough you'll almost never run into a bug that can't wait until the next official release. I've worked on other projects where we never could have gotten away with that, but due to the lightweight development process and low ceremony we were able to use a lightweight version control policy very effectively. I'll also mention that everything I've written is coming from an enterprise IT context where there's only a single production instance of a given code base. If I was working on a product that was deployed at 100 different customer sites the branching and tagging practices would have to be a little more strenuous in order to manage all of the independent update cycles across all the instances.
I can't comment on other source control software but after using VSS 6.0 , StarTeam, Vault and SVN I cannot rate SVN + Tortoise more highly. AnkhSVN is a free plug-in for Visual studio which I personally didn't warm to. Apparently Visual SVN is much better but costs money.
The xUnit family are the mainstay of unit testing. They are integrated into the likes of Netbeans, Eclipse and many other IDEs. They offer a simple, structured solution to unit testing. One thing I always try and do when writing a test is to minimise external code usage. By that I mean: I try to minimise the setup and teardown code for the test as much as possible and try to avoid using other modules/code blocks as much as possible. Well-written modular code shouldn't require too much external code in it's setup and teardown.
The so-called [xUnit][1] framework is widely used. It was originally developed for Smalltalk as SUnit, evolved into JUnit for Java, and now has many other implementations such as NUnit for .Net. It's almost a de facto standard - if you say you're using unit tests, a majority of other developers will assume you mean xUnit or similar. [1]: http://en.wikipedia.org/wiki/XUnit
> What about external dependencies such a the AJAXTookit or some other 3rd party extension that's used on several projects? Source control is for source code, not binaries. Keep any 3rd party assemblies/jars in a separate repository. If you're working in the Java world try something like Maven or Ivy. For .Net projects a simple shared drive can work well as long as you have decent policies around how it's structured and updated.
In PHP, I'm using this one and I'll appreciate every comment about it : function quote_smart($valeur) { if (get_magic_quotes_gpc()) $valeur = stripslashes($valeur); if (!is_numeric($valeur)) $valeur = mysql_real_escape_string($valeur); return $valeur; } $IdS = quote_smart($_POST['theID']); $sql = " SELECT * FROM Students WHERE IdStudent={$IdS}; "; Needs one more verification if a field can be NULL : $picture = NULL; $theidyouwant = 7; $Name = 'WOOD'; if(is_null($picture)) $p = 'NULL'; else $p = "'".quote_smart($picture)."'"; $IdS = quote_smart($theidyouwant); $requete = "SELECT * FROM Students WHERE IdStudent={$IdS} AND PictureStudent={$p} AND NameStudent='{$Name}'; "; That's it enjoy ! (hope the post will correctly send underscores and not &#95 ;)
<http://www.opensourcetemplates.org/> has nice designs, just not enough selection.
A great thing to use in PHP is the [PDO][1]. It takes a lot of the guesswork out of dealing with securing your SQL (and all of your SQL stuff in general). It supports prepared statements, which go a long way towards thwarting SQL Injection Attacks. A great primer on PDO is included in the book [The PHP Anthology 101 Essential Tips, Tricks & Hacks by Davey Shafik etc. 2nd Ed][2]. Makes learning a breeze and is excellent as a reference. I don't even have to think about anything other than the actual SQL Query anymore. [1]: http://us2.php.net/pdo [2]: http://www.amazon.com/PHP-Anthology-Essential-Tricks-Hacks/dp/0975841998/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1217964439&sr=8-1
To retrieve the number of widgets from each widget category that has more than 5 widgets, you could do this: <pre><code> SELECT WidgetCategory, count(*) FROM Widgets GROUP BY WidgetCategory HAVING count(*) > 5 </code></pre> The "having" clause is something people often forget about, instead opting to retrieve all their data to the client and iterating through it there.
I was wrestling with this problem several years ago (2004 I think). We ran into the problem that Firefox doesn't allow scripts to read the clipboard by default (but you can [grant access to the clipboard][1]). There's other ways of reading the clipboard data as well...Flash, for instance, can read the clipboard. There's a good article on [ajaxian][2] to explain how do to this behind the scenes. In the end, we couldn't find a web-based Grid that fit the bill, so we had to create our own in a mixture of Actionscript and Javascript. [1]: http://support.mozilla.com/en-US/kb/Granting+JavaScript+access+to+the+clipboard [2]: http://ajaxian.com/archives/auto-copy-to-clipboard
For maximum security, performance, and correctness use prepared statements. Here's how to do this with lots of examples in different languages, including PHP: <http://stackoverflow.com/questions/1973/what-is-the-best-way-to-avoid-sql-injection-attacks>