instruction
stringlengths
0
30k
|hosting|web-applications|
I am a broke college student. I have built a small web app in PHP5 and MySQL, and I already have a domain. What is an affordable way to get it online? A few people have suggested amazon's cloud services, but that seems equivalent to slitting my wrists and watching money slowly trickle out. So suggestions? Hosting companies, CIA drop sites, anything?
|web-applications|hosting|
I am a broke college student. I have built a small web app in PHP5 and MySQL, and I already have a domain. What is an affordable way to get it online? A few people have suggested amazon's cloud services, but that seems equivalent to slitting my wrists and watching money slowly trickle out. So suggestions? Hosting companies, CIA drop sites, anything? **Update:** A lot of suggestions have been for Dreamhost. Their plan allows for 5TB of bandwidth. Could anyone put this in perspective? For instance, how much bandwidth does a site with the kind of traffic StackOverflow get?
Check out [http://www.codeproject.com/KB/vb/vcalendar.aspx][1] [1]: http://www.codeproject.com/KB/vb/vcalendar.aspx It doesn't handle the quoted-printable fields like you asked, but the rest of the code is there and can be modified.
Oracle: select * from (select foo from bar order by foo) where ROWNUM = x
Personally I use PDO, but I think that is mainly a question of preference. PDO has some features that help agains SQL injection ([prepared statements][1]), but if you are careful with your SQL you can achieve that with mysqli, too. Moving to another database is not so much a reason to use PDO. As long as you don't use "special SQL features", you can switch from one DB to another. However as soon as you use for example "SELECT ... LIMIT 1" you can't go to MS-SQL where it is "SELECT TOP 1 ...". So this is problematic anyway. [1]: http://de.php.net/manual/de/pdo.prepared-statements.php
find orphaned methods in codebase
My GPS logger occassionally leaves "unfinished" lines at the end of the log files. I think they're only at the end, but I want to check all lines just in case. A sample complete sentence looks like: $GPRMC,005727.000,A,3751.9418,S,14502.2569,E,0.00,339.17,210808,,,A*76 The line should start with a `$` sign, and end with an `*` and a two character hex checksum. I don't care if the checksum is correct, just that it's present. It also needs to ignore "ADVER" sentences which don't have the checksum and are at the start of every file. The following Python code might work: import re from path import path nmea = re.compile("^\$.+\*[0-9A-F]{2}$") for log in path("gpslogs").files("*.log"): for line in log.lines(): if not nmea.match(line) and not "ADVER" in line: print "%s\n\t%s\n" % (log, line) Is there a way to do that with `grep` or `awk` or something simple? I haven't really figured out how to get `grep` to do what I want. Thanks.
|grep|gps|nmea|regex|
|regex|grep|gps|nmea|
My GPS logger occassionally leaves "unfinished" lines at the end of the log files. I think they're only at the end, but I want to check all lines just in case. A sample complete sentence looks like: $GPRMC,005727.000,A,3751.9418,S,14502.2569,E,0.00,339.17,210808,,,A*76 The line should start with a `$` sign, and end with an `*` and a two character hex checksum. I don't care if the checksum is correct, just that it's present. It also needs to ignore "ADVER" sentences which don't have the checksum and are at the start of every file. The following Python code might work: import re from path import path nmea = re.compile("^\$.+\*[0-9A-F]{2}$") for log in path("gpslogs").files("*.log"): for line in log.lines(): if not nmea.match(line) and not "ADVER" in line: print "%s\n\t%s\n" % (log, line) Is there a way to do that with `grep` or `awk` or something simple? I haven't really figured out how to get `grep` to do what I want. **Update**: Thanks @Motti and @Paul, I was able to get the following to do almost what I wanted, but had to use single quotes and remove the trailing `$` before it would work: grep -nvE '^\$.*\*[0-9A-F]{2}' *.log | grep -v ADVER | grep -v ADPMB Two further questions arise, how can I make it ignore blank lines? And can I combine the last two `grep`s?
# Haskell: Functional fact 0 = 1 fact n = n * fact (n-1)
There are already various [classes][1] [available][2] for this so you may wish to look at them before writing your own solution (if indeed writing your own solution is still needed). [1]: http://www.pear.php.net/package/Crypt_DiffieHellman/docs/latest/Crypt_DiffieHellman/BigInteger/Crypt_DiffieHellman_Math_BigInteger_Interface.html [2]: http://pear.php.net/package/Math_BigInteger/docs/latest/Math_BigInteger/_Math_BigInteger-1.0.0RC3---BigInteger.php.html
What is the best way to interpret Perfmon analysis into application specific observations/data?
have a look at the [jquery][1] cross browser javascript library for animation (it is what is used on stackoverflow). The reference for it can be found <http://visualjquery.com/1.1.2.html> Unfortunately with out flash silverlight or another plug in cross system video support is limited. [1]: http://jquery.com/
Yes. I am working on an Editor. It's a XAML-like language (or OpenLaszlo-like, if you prefer) for XNA. So the buttons can be resized by the editor. The buttons might also be resized by a style sheet. I guess you're right that it's likely that the buttons will all be the same size in a real design. But even in a window's app, you sometimes need to make a button wider to accomodate text.
You'll get different results for the different methods depending on whether you compile with optimisations on. You basically have a few options: object o; //checking with is o is int //check type o.GetType() != typeof( int ) //cast and catch exception try{ int j = (int) o; } catch {} //use the tryparse int.TryParse( Convert.ToString( o ), out j ) You can easily set up a console app that tries each of these 10,000 times and returns durations for each (test when o is an int and when it's something else). The `try-catch` method is the quickest if the object does hold an int, and by far the slowest if it doesn't (even slower than `GetType`). `int.TryParse` is pretty quick if you have a string, but if you have an unknown object it's slower. Interestingly, with .Net 3.5 and optimisations turned on the `o is int` check takes the same time as `try-catch` when o actually is an int. `o is int` is only slightly slower if o actually is something else. Annoyingly FxCop will throw up warnings if you do something like: if( o is int ) int j = (int) o; But I think that's a bug in FxCop - it doesn't know int is a value type and recommends you to use `o as int` instead. If your input is always a string `int.TryParse` is best, otherwise the `is` operator is quickest. As you have a string I'd look at whether you need to know that it's an int, rather than a double. If `int.TryParse` passes then so will `double.TryParse` so you could half the number of checks - return either double or string and floor the doubles when you expect an int.
@lassevk I found the referenced article, from DDJ: [The Maximal Rectangle Problem][1] [1]: http://www.ddj.com/184410529
i belive there is now a firebug lite that works on other browsers such as ie.
There is now a [Firebug Lite][1] that works on other browsers such as ie, safari and opera built it does have a limited set of commands and is not as full as the version in firefox. If you are using asp.net in visual studio 2008 will also debug JavaScript in IE. [1]: http://getfirebug.com/lite.html
If the junior programmer, or anyone, doesn't see the value in testing, then it will be hard to get them to do it...period. I would have made the junior programmer sacrifice their weekend to fix the bug. His actions (or lack there of) are not affecting him directly. Also, make it apparent, that he will not see advancement and/or pay increases if he doesn't improve his skills in testing. In the end, even with all your help, encouragement, mentoring, he might not be a fit for your team, so let him go and look for someone who does get it.
I had to write a basic Gnutella client in C# using Web Services and I think the class notes on the P2P stuff are still available [here][1] and [here][2]. [1]: http://www.cs.virginia.edu/~humphrey/cs451/ClassNotes/CS451_DisSys_0327.pdf [2]: http://www.cs.virginia.edu/~humphrey/cs451/ClassNotes/CS451_DisSys_0329.pdf
This entirely depends on what varies and what stays the same. For example, I am working on a (non-OOP) [framework](http://www.seqan.de/) where the find algorithm is different depending both on the type of the needle and the haystack. Apart from the fact that this would require double-dispatch in an object-oriented environment, it also means that it isn't meaningful to write either `needle.find(haystack)` or to write `haystack.find(needle)`. On the other hand, your application could happily delegate finding to either of both classes, or stick with one algorithm altogether in which case the decision is arbitrary. In that case, I would prefer the `haystack.find(needle)` way because it seems more logical to apply the finding to the haystack.
Personally, I like the second method. My reasoning is because the major APIs I have worked with use this approach, and I find it makes the most sense. If you have a list of things (haystack) you would search for (find()) the needle.
I would say that option 1 is completely out. The code should read in a way that tells you what it does. Option 1 makes me think that this needle is going to go find me a haystack. Option 2 looks good if a haystack is meant to contain needles. ListCollections are always going to contain ListItems, so doing collection.find(item) is natural and expressive. I think the introduction of a helper object is approproiate when: 1. You don't control the implementation of the objects in question IE: search.find(ObsecureOSObject, file) 2. There isn't a regular or sensible relationship between the objects IE: nameMatcher.find(houses,trees.name)
Man, they have VS 2008 project template listed in their [release notes][1]. I guess that doesn't mean they have it integrated with the dialog yet. I use [MbUnit][2] with [Gallio][3] and everything worked like a charm. I had to install an Alpha of Gallio and MbUnit and when I read the above in the release notes, I figured they implemented it also. Just keep a look out on nUnit's site for future alpha releases. I am sure they'll have it implemented soon. You could also implement the feature yourself and submit a patch. :-) [1]: http://nunit.com/index.php?p=releaseNotes&r=2.5 [2]: http://www.mbunit.com/ [3]: http://www.gallio.org/
**Turn off the annoying RSS reader** * Tools, Options, Environment, Startup **Turn off all the animations** * Tools, Options, Environment, Animate Environment Tools **Install the [recent Service Pack][1]** **Clean out your WebCache** * AppData\Local\Microsoft\WebSiteCache [1]: http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx
Usually actions should be applied to what you are doing the action on... in this case the haystack, so I think option 2 is the most appropriate. You also have a fourth alternative that I think would be better than alternative 3: haystack.find(needle, searcher) In this case, it allows you to provide the manner in which you want to search as part of the action, and so you can keep the action with the object that is being operated on.
|.net|performance|perfmon|
Many of us have used Perfmon tool to do performance analysis. Especially with .Net counters, but there are so many variables going on in Perfmon, that it always becomes hard to interpret Perfmon results in to valuable feedback about my application. I want to use perfmon, (not a tool like [Ants Profiler][1] etc) but how do I accurately interpret the observations? Any inputs are welcome. [1]: http://www.red-gate.com/products/ants_profiler/index.htm
Get back to basics. How do I get back into C++?
|c++|
I haven't used C++ since college. Even though I've wanted to I haven't needed to do any until I started wanting to write plugins for Launchy. Is there a good book to read to get back into it? My experience since college is mainly C# and recently ruby. I bought some book for C# developers and it ended up being on how to write C++ with CLI. While a good book it wasn't quite what I was looking for.
Have you tried the [MySQL Query Browser][1]? Works cross platform and is much nicer than the plain shell. [1]: http://www.mysql.com/products/tools/query-browser/
It's right under your nose: List<TableItem> myResult = (from t in db.Table select t).ToList(); Now, just cache myResult as you would have cached your old DAL's returned data.
As far as I can tell, the bcmath extension is the one you'll want. The data in the PHP manual is a little sparse, but you out to be able to set the precision to be exactly what you need by using the bcscale() function, or the optional third parameter in most of the other bcmath functions. Not too sure on the binary strings thing, but a bit of googling tells me you ought to be able to do with by making use of the pack() function.
> I traced through the external assembly with Reflector and found no evidence of threading whatsoever. **You can't find any threading does not mean there is no threading** .NET has a 'thread pool' which is a set of 'spare' threads that sit around mostly idle. Certain methods cause things to run in one of the thread pool threads so they don't block your main app. The blatant examples are things like [ThreadPool.QueueUserWorkItem](http://msdn.microsoft.com/en-us/library/system.threading.threadpool.queueuserworkitem.aspx), but there are lots and lots of other things which can also run things in the thread pool that don't look so obvious, like [Delegate.BeginInvoke](http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx) Really, you need to [do what kibbee suggests](http://stackoverflow.com/questions/36014/why-is-net-exception-not-caught-by-trycatch-block#36048).
PostgreSQL also uses MVCC (Multi-Version Concurrency Control), so using the default transaction isolation level (read-committed), you should never block, unless somebody is doing maintainace on th DB (dropping / adding columns / tables / indexes / etc).
A hard keep like you have is only going to fix the size at initialization but elements could still be added or dropped later, are you trying to guard against this condition? The only way I can think of to guarantee that elements aren't added or dropped later is emitting an event synced on the size != the predetermined amount: event list_size_changed is true (wanted.size() != 5) @clk; The only other thing that I can offer is a bit of syntactic sugar for the hard keep: var warned : list of bool; keep warned.size() == 5;
**Don't worry about DNS.** You should have there just static entry like: A *.YOURDOMAIN.COM [IPADDRESS] Ask your DNS provider to do it for you (if it's not done already) or do it by yourself if you have control over your DNS records. This will automatically point all your subdomains (current and future ones) into the same HTTP server. Once it's done, you will need to parse HOST header in your web application on every single HTTP request to detect what client is accessing your server and display appropriate html. Depends what server-side language/framework you're using, it's usually very simple. For example, assuming you're using ASP.NET, then you might have a file Secret.aspx in your application root. http://client1.mydomain.com/Secret.aspx and http://client2.mydomain.com/Secret.aspx will be pointing to the very same file. You decide what you show once this file is requested based on HOSTNAME parameter.
**Don't worry about DNS and URL rewriting** Your DNS record will be static, something like: A *.YOURDOMAIN.COM [IPADDRESS] Ask your DNS provider to do it for you (if it's not done already) or do it by yourself if you have control over your DNS records. This will automatically point all your subdomains (current and future ones) into the same HTTP server. Once it's done, you will only need to parse HOST header on every single HTTP request to detect what hostname is used to access your server-side scripts.
**Don't worry about DNS and URL rewriting** Your DNS record will be static, something like: A *.YOURDOMAIN.COM [IPADDRESS] Ask your DNS provider to do it for you (if it's not done already) or do it by yourself if you have control over your DNS records. This will automatically point all your subdomains (current and future ones) into the same HTTP server. Once it's done, you will only need to parse HOST header on every single http request to detect what hostname was used to access your server-side scripts on your http server. Assuming you're using ASP.NET, this is kind of silly example I came up with but works and demonstrates simplicity of this approach: <%@ Language="C#" %> <% string subDomain = Request.Url.Host.Split('.')[0].ToUpper(); if (subDomain == "CLIENTXXX") Response.Write("Hello CLIENTXXX, your secret number is 33"); else if (subDomain == "CLIENTYYY") Response.Write("Hello CLIENTYYY, your secret number is 44"); else Response.Write(subDomain+" doesn't exist"); %>
**Don't worry about DNS and URL rewriting** Your DNS record will be static, something like: *.YOURDOMAIN.COM A 123.123.123.123 Ask your DNS provider to do it for you (if it's not done already) or do it by yourself if you have control over your DNS records. This will automatically point all your subdomains (current and future ones) into the same HTTP server. Once it's done, you will only need to parse HOST header on every single http request to detect what hostname was used to access your server-side scripts on your http server. Assuming you're using ASP.NET, this is kind of silly example I came up with but works and demonstrates simplicity of this approach: <%@ Language="C#" %> <% string subDomain = Request.Url.Host.Split('.')[0].ToUpper(); if (subDomain == "CLIENTXXX") Response.Write("Hello CLIENTXXX, your secret number is 33"); else if (subDomain == "CLIENTYYY") Response.Write("Hello CLIENTYYY, your secret number is 44"); else Response.Write(subDomain+" doesn't exist"); %>
|codebase|codesearch|unusedcode|
I'm sure we've all seen it before...A code base that has been around for a year or two, and as features have been added and bugs fixed, we end up with pieces of code that aren't actually in use anymore. I'm wondering if there is a way (especially in VS.NET with or without a third-party tool) to search the codebase and show me which methods are NEVER used anywhere else in the code? The one challenge I can think of in regards to this type of utility would be the inability to map back when implicit type conversions are occuring. But assuming that wasn't a problem, what are my options?
|visual-studio|refactoring|
|.net|visual-studio|refactoring|
For build automation and continuous integration take a look at [TeamCity][1] from [Jetbrains][2]. It has a lot of [features][3] and is really a breeze to set up and use. If you use Visual Studio 2005/2008 it will build your solution directly without the need for extra scripts (if a build is all you want.) It will also execute your unit tests and gather stats on build success, unit test execution times, etc, etc. Best of all: The Pro edition is free for teams with up to 20 users and 3 build agents. [1]: http://www.jetbrains.com/teamcity/ [2]: http://www.jetbrains.com [3]: http://www.jetbrains.com/teamcity/documentation/featureMatrix.html
Some of my team's new systems generate RSS feeds that the developers syndicate. These feeds push out events that interest the developers at certain times and the information is controlled using different loggers. Thus when debugging you can get the debugging feed, when you want to see completed transactions you go to the transactions feeds etc. This allows all the developers to get the information they want in a comfortable way and without any need to mess a lot with configuration. If you don't want to get it there's no need to remove yourself from a mailing list or edit a configuration file - simply remove the feed and *be done with it*. Very cool, and the idea was stolen from Pragmatic Project Automation.
> Are there any good tutorials on how to integrate OpenId with an ASP.NET site? [Andrew Arnott's post titled "How to add OpenID to your ASP.NET web site (in C# or VB.NET)"][1] [1]: http://blog.nerdbank.net/2008/04/how-to-add-openid-to-your-aspnet-web.html
I do not know whether the above answer does basically the same thing, but some of our systems use the DB connection about once a week and I've seen that we provide a -Otimeout flag or something of that sort to mysql to set the connection timeout.
But really, isn't all this really just parlor tricks for good database design in the first place? The few times I needed functionality like this it was for a simple one off query to make a quick report. For any real work, using tricks like these is inviting trouble. If selecting a particular row is needed then just have a column with a sequential value and be done with it.
In Sybase SQL Anywhere: SELECT TOP 1 START AT n * from table ORDER BY whatever Don't forget the ORDER BY or it's meaningless.
C and C++ compilers will generate a warning when you compare signed and unsigned types; in your example code, you couldn't make your loop variable unsigned and have the compiler generate code without warnings (assuming said warnings were turned on). Naturally, you're compiling with warnings turned all the way up, right? And, have you considered compiling with "treat warnings as errors" to take it that one step further? The downside with using signed numbers is that there's a temptation to overload them so that, for example, the values 0->n are the menu selection, and -1 means nothing's selected - rather than creating a class that has two variables, one to indicate if something is selected and another to store what that selection is. Before you know it, you're testing for negative one all over the place and the compiler is complaining about how you're wanting to compare the menu selection against the number of menu selections you have - but that's dangerous because they're different types. So don't do that.
The way we do this is to have a 'catch all' for our domain name registered in DNS so that anything.ourdomain.com will point to our server. With Apache you can set up a similar catch-all for your vhosts. The ServerName must be a single static name but the ServerAlias directive can contain a pattern. Servername www.ourdomain.com ServerAlias *.ourdomain.com Now all of the domains will trigger the vhost for our project. The final part is to decode the domain name actually used so that you can work out the username in your code, something like (PHP): list( $username ) = explode( ".", $_SERVER[ "HTTP_HOST" ] ); or a RewriteRule as already suggested that silently maps user.ourdomain.com/foo/bar to www.ourdomain.com/foo/bar?user=user or whatever you prefer.
I have written a NAnt build file that handles parsing SVN information and creating properties. I then use those property values for a variety of build tasks, including setting the label on the build. I use this target combined with the SVN Revision Labeller mentioned by lubos hasko with great results. <target name="svninfo" description="get the svn checkout information"> <property name="svn.infotempfile" value="${build.directory}\svninfo.txt" /> <exec program="${svn.executable}" output="${svn.infotempfile}"> <arg value="info" /> </exec> <loadfile file="${svn.infotempfile}" property="svn.info" /> <delete file="${svn.infotempfile}" /> <property name="match" value="" /> <regex pattern="URL: (?'match'.*)" input="${svn.info}" /> <property name="svn.info.url" value="${match}"/> <regex pattern="Repository Root: (?'match'.*)" input="${svn.info}" /> <property name="svn.info.repositoryroot" value="${match}"/> <regex pattern="Revision: (?'match'\d+)" input="${svn.info}" /> <property name="svn.info.revision" value="${match}"/> <regex pattern="Last Changed Author: (?'match'\w+)" input="${svn.info}" /> <property name="svn.info.lastchangedauthor" value="${match}"/> <echo message="URL: ${svn.info.url}" /> <echo message="Repository Root: ${svn.info.repositoryroot}" /> <echo message="Revision: ${svn.info.revision}" /> <echo message="Last Changed Author: ${svn.info.lastchangedauthor}" /> </target>
If you don't want to use an installer and you don't want the user to perform any extra steps to allow CHM files over the network, why not fall back to WinHelp? Vista does not include WinHlp32.exe out of the box, but it is [freely available as a download][1] for both Vista and Server 2008. [1]: http://support.microsoft.com/kb/917607
How do I setup Public-Key Authentication?
|linux|ssh|
How do I setup Public-Key Authentication for SSH?
Your code worked fine in VB.Net because it implicitly does any casts, while C# has both implicit and explicit ones. In C# the conversion from decimal to double is explicit as you lose accuracy. For instance 1.1 can't be accurately expressed as a double, but can as a decimal (<a href="http://bizvprog.blogspot.com/2008/05/floating-point-numbers-more-inaccurate.html">reason why</a>). In VB the conversion was added for you by the compiler: decimal trans = trackBar1.Value / 5000m; this.Opacity = (double) trans; That (double) has to be explicitly stated in C#, but can be *implied* by VB's more 'forgiving' compiler.
Frankly, if you are having to put *that* much effort into getting him to do something then you may have to come to terms with the thought that he may just not be a good fit for the team, and may need to go. Now, this doesn't necessarily mean firing him... it may mean finding someplace else in the company his skills are more suited. But if there is no place else...you know what to do. I'm assuming he is also a fairly new hire (< 1 year) and probably recently out of school...in which case he may not be accustomed to how things work in a corporate setting. Things like that most of us could get away with in college. If this is the case, one thing I've found works is to have a sort of "surprise new hire review." It doesn't matter if you've never done it before...he won't know that. Just sit him down and tell him your are going to go over his performance and show him some real numbers...take your normal review sheet (you do have a formal review process right?) and change the heading if you want so it looks official and show him where he stands. If you show him in a very formal setting that not doing tests is adversely affecting his performance rating as opposed to just "nagging" him about it, he will hopefully get the point. You've got to show him that his actions will actually affect him be it pay wise or otherwise. I know, you may want to stay away from doing this because it's not official... but I think you are within reason to do it and it's probably going to be a whole lot cheaper than having to fire him and recruit someone new.
I've noticed that a lot of programmers see the value of testing on a rational level. If you've heard things like "yeah, I know I should test this but I really need to get this done quickly" then you know what I mean. However, on an emotional level they feel that they get something done only when they're writing the real code. The goal, then, should be to somehow get them to understand that testing is in fact the **only** way to measure when something is "done", and thus give them the intrinsic motivation to write tests. I'm afraid that's a lot harder than it should be, though. You'll hear a lot of excuses along the lines of "I'm in a real hurry, I'll rewrite/refactor this later and then add the tests" -- and of course, the followup never happens because, surprisingly, they're *just as busy the next week*.
How can I identify in which Java Applet context I'm running without passing an ID?
|java|swing|applet|
I've seen lots of examples of making an entire regular expression case-insensitive. What I'm wondering about is having just part of the expression be case-insensitive. For example, let's say I have a string like this: fooFOOfOoFoOBARBARbarbarbAr What if I want to match all occurrences of "foo" regardless of case but I only want to match the upper-case "BAR"s? The ideal solution would be something that works across regex flavors but I'm interested in hearing language-specific ones as well (Thanks [Espo](http://stackoverflow.com/questions/43632/can-you-make-just-part-of-a-regex-case-insensitive#43636)) ***Edit*** The link Espo provided was very helpful. There's a neat bit in there about turning modifiers on and off within the expression. For my contrived exampled, I can do something like this: (?i)foo*(?-i)|BAR which makes the match case-insensitive for just the foo portion of the match. That seemed to work in most regex implementations except Javascript, Python, and few others (as Espo mentioned). The big ones that I wondered about (Perl, PHP, .NET) all support inline mode changes.
I've seen lots of examples of making an entire regular expression case-insensitive. What I'm wondering about is having just part of the expression be case-insensitive. For example, let's say I have a string like this: fooFOOfOoFoOBARBARbarbarbAr What if I want to match all occurrences of "foo" regardless of case but I only want to match the upper-case "BAR"s? The ideal solution would be something that works across regex flavors but I'm interested in hearing language-specific ones as well (Thanks [Espo](http://stackoverflow.com/questions/43632/can-you-make-just-part-of-a-regex-case-insensitive#43636)) ***Edit*** The link Espo provided was very helpful. There's a good example in there about turning modifiers on and off within the expression. For my contrived example, I can do something like this: (?i)foo*(?-i)|BAR which makes the match case-insensitive for just the foo portion of the match. That seemed to work in most regex implementations except Javascript, Python, and few others (as Espo mentioned). The big ones that I was wondering about (Perl, PHP, .NET) all support inline mode changes.
I've seen lots of examples of making an entire regular expression case-insensitive. What I'm wondering about is having just part of the expression be case-insensitive. For example, let's say I have a string like this: fooFOOfOoFoOBARBARbarbarbAr What if I want to match all occurrences of "foo" regardless of case but I only want to match the upper-case "BAR"s? The ideal solution would be something that works across regex flavors but I'm interested in hearing language-specific ones as well (Thanks [Espo](http://stackoverflow.com/questions/43632/can-you-make-just-part-of-a-regex-case-insensitive#43636)) ***Edit*** The link Espo provided was very helpful. There's a good example in there about turning modifiers on and off within the expression. For my contrived example, I can do something like this: (?i)foo*(?-i)|BAR which makes the match case-insensitive for just the foo portion of the match. That seemed to work in most regex implementations except Javascript, Python, and a few others (as Espo mentioned). The big ones that I was wondering about (Perl, PHP, .NET) all support inline mode changes.
Good strategy for leaving an audit trail/change history for DB applications?
|database|database-design|postgresql|
What are some strategies that people have had success with for maintaining a change history for data in a fairly complex database. One of the applications that I frequently use and develop for could really benefit from a more comprehensive way of tracking how records have changed over time. For instance, right now records can have a number of timestamp and modified user fields, but we currently don't have a scheme for logging multiple change, for instance if an operation is rolled back. In a perfect world, it would be possible to reconstruct the record as it was after each save, etc. Some info on the DB: - Needs to have the capacity to grow by thousands of records per week - 50-60 Tables - Main revisioned tables may have several million records each - Reasonable amount of foreign keys and indexes set - Using PostgreSQL 8.x
I agree that **SSRS** is generally the right choice. But for flashy and embedded in an HTML page, I like [Dundas][1]. Their stuff looks good out of the box, has an easy-to-understand API, and is painless to get up and running. [1]: http://www.dundas.com/
In the past I have used triggers to construct db update/insert/delete logging. You could insert a record each time one of the above actions is done on a specific table into a logging table that keeps track of the action, what db user did it, timestamp, table it was preformed on, and previous value. There is probably a better answer though as this would require you to cache the value before the actual delete or update was preformed I think. But you could use this to do rollbacks.
Unless Apache and PHP have some option to utilize memcached for internal workings (of which I am unaware of), you typically don't "enable" it for such apps. Instead, you would get a [client library][1] to use memcached from within your application, then start up memcached on whatever servers you want to provide memory with, then just use the client library API to store and retrieve cached data across multiple servers. [1]: http://www.danga.com/memcached/apis.bml
One strategy you could use is MVCC, Multi-Value Concurrency Control. In this scheme, you never do updates to any of your tables, you just do inserts, maintaining version numbers for each record. This has the advantage of providing an exact snapshot from any point in time, and it also completely sidesteps the update lock problems that plague many databases. But it makes for a huge database, and selects all require an extra clause to select the current version of a record.
A language agnostic algorithm would be as follows: function getNthColumnName(int n) { let curPower = 1 while curPower < n { set curPower = curPower * 26 } let result = "" while n > 0 { let temp = n / curPower let result = result + char(temp) set n = n - (curPower * temp) set curPower = curPower / 26 } return result This algorithm also takes into account if Excel gets upgraded again to handle more than 16k columns. If you really wanted to go overboard, you could pass in an additional value and replace the instances of 26 with another number to accomodate alternate alphabets
Regex to pull out a section of text from a file
|regex|
If i have a file like the following: > Data Data > Data > [Start] > Data i want > [End] > Data Whats the regex to pull out the data between the [start] and [end] tags
Regex: To pull out a section a substing from a string between two tags
Link to http://www.whatever.com/hello.ppt**#4** for slide 4 to be opened initially. [Reference][1] [1]: http://www.tinyempire.com/shortnotes/files/specific_slide_in_ppt.htm
\[start\]\s*(((?!\[start\]|\[end\]).)+)\s*\[end\] This should hopefully drop the [start] and [end] markers as well.
It sounds like ADO/Access is perfect for your needs. It's baked into the MS stack, well seasoned, and multi-user. You can programatically create a DB like so: Dim catalog as New ADOX.Catalog Catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\server\path\to\db.mdb") You can then use standard ADO.NET methods.
It sounds like ADO/Access is perfect for your needs. It's baked into the MS stack, well seasoned, and multi-user. You can programatically create a DB like so: Dim catalog as New ADOX.Catalog Catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\server\path\to\db.mdb") You can then use standard ADO.NET methods to interact with the database.
Jeff, your code is nice but could be clearer with constants (as suggested in Code Complete). const int SECOND = 1; const int MINUTE = 60 * SECOND; const int HOUR = 60 * MINUTE; const int DAY = 24 * HOUR; const int MONTH = 30 * DAY; if (delta < 1 * MINUTE) { return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago"; } if (delta < 2 * MINUTE) { return "a minute ago"; } if (delta < 45 * MINUTE) { return ts.Minutes + " minutes ago"; } if (delta < 90 * MINUTE) { return "an hour ago"; } if (delta < 24 * HOUR) { return ts.Hours + " hours ago"; } if (delta < 48 * HOUR) { return "yesterday"; } if (delta < 30 * DAY) { return ts.Days + " days ago"; } if (delta < 12 * MONTH) { int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30)); return months <= 1 ? "one month ago" : months + " months ago"; } else { int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365)); return years <= 1 ? "one year ago" : years + " years ago"; }
In C#, int is just an alias for System.Int32, string for System.String, double for System.Double etc... Personally I prefer int, string, double, etc. because they don't require a "using System;" statement :) A silly reason, I know...
In C#, int is just an ***alias*** for System.Int32, string for System.String, double for System.Double etc... Personally I prefer int, string, double, etc. because they don't require a "using System;" statement :) A silly reason, I know...
Lambda comes from the [Lambda Calculus](http://en.wikipedia.org/wiki/Lambda_calculus) and refers to anonymous functions in programming. Why is this cool? It allows you to write quick throw away functions without naming them. It also provides a nice way to write closures. With that power you can do things like this. def adder(x): return lambda y: x + y add5 = adder(5) add5(1) 6 As you can see from the snippet of python, the function adder takes in an argument x, and returns an anonymous function, or lambda, that takes another argument y. That anonymous function allows you to create functions from functions. This is a simple example, but it should convey the power lambdas and closures have.
Lambda comes from the [Lambda Calculus](http://en.wikipedia.org/wiki/Lambda_calculus) and refers to anonymous functions in programming. Why is this cool? It allows you to write quick throw away functions without naming them. It also provides a nice way to write closures. With that power you can do things like this. Python def adder(x): return lambda y: x + y add5 = adder(5) add5(1) 6 Javascript adder = function (x) { return function (y) { x + y } }; add5 = adder(5); add5(1) == 6 As you can see from the snippet of python and js, the function adder takes in an argument x, and returns an anonymous function, or lambda, that takes another argument y. That anonymous function allows you to create functions from functions. This is a simple example, but it should convey the power lambdas and closures have.
Lambda comes from the [Lambda Calculus](http://en.wikipedia.org/wiki/Lambda_calculus) and refers to anonymous functions in programming. Why is this cool? It allows you to write quick throw away functions without naming them. It also provides a nice way to write closures. With that power you can do things like this. **Python** def adder(x): return lambda y: x + y add5 = adder(5) add5(1) 6 **Javascript** adder = function (x) { return function (y) { x + y } }; add5 = adder(5); add5(1) == 6 As you can see from the snippet of python and js, the function adder takes in an argument x, and returns an anonymous function, or lambda, that takes another argument y. That anonymous function allows you to create functions from functions. This is a simple example, but it should convey the power lambdas and closures have.
Lambda comes from the [Lambda Calculus](http://en.wikipedia.org/wiki/Lambda_calculus) and refers to anonymous functions in programming. Why is this cool? It allows you to write quick throw away functions without naming them. It also provides a nice way to write closures. With that power you can do things like this. **Python** def adder(x): return lambda y: x + y add5 = adder(5) add5(1) 6 **Javascript** adder = function (x) { return function (y) { x + y } }; add5 = adder(5); add5(1) == 6 **Scheme** (define adder (lambda (x) (lambda (y) (+ x y)))) (define add5 (adder 5)) (add5 1) 6 As you can see from the snippet of python and js, the function adder takes in an argument x, and returns an anonymous function, or lambda, that takes another argument y. That anonymous function allows you to create functions from functions. This is a simple example, but it should convey the power lambdas and closures have.
I'm part of a team that develops a pretty big Swing Java Applet. Most of our code is legacy and there are tons of singleton references. We've bunched all of them to a single "application context" singleton. What we now need is to create some way to separate the shared context (shared across all applets currently showing) and non-shared context (specific to each applet currently showing). However, we don't have an ID at each of the locations that call to the singleton, nor do we want to propagate the ID to all locations. What's the easiest way to identify in which applet context we're running? (I've tried messing with classloaders, thread groups, thread ids... so far I could find nothing that will enabled me to ID the origin of the call).
SVN 1.5 introduced the concept of automatic merge tracking, although I thought it required a 1.5 server and client. See [here](http://subversion.tigris.org/svn_1.5_releasenotes.html#merge-tracking) for details.
The complexities of pointers go beyond what we can easily teach. Having students point to each other and using pieces of paper with house addresses are both great learning tools. They do a great job of introducing the basic concepts. Indeed, learning the basic concepts is *vital* to successfully using pointers. However, in production code, it's common to get into much more complex scenarios than these simple demonstrations can encapsulate. I've been involved with systems where we had structures pointing to other structures pointing to other structures. Some of those structures also contained embedded structures (rather than pointers to additional structures). This is where pointers get really confusing. If you've got multiple levels of indirection, and you start ending up with code like this: widget->wazzle.fizzle = fazzle.foozle->wazzle; it can get confusing really quickly (imagine a lot more lines, and potentially more levels). Throw in arrays of pointers, and node to node pointers (trees, linked lists) and it gets worse still. I've seen some really good developers get lost once they started working on such systems, even developers who understood the basics really well. Complex structures of pointers don't necessarily indicate poor coding, either (though they can). Composition is a vital piece of good object-oriented programming, and in languages with raw pointers, it will inevitably lead to multi-layered indirection. Further, systems often need to use third-party libraries with structures which don't match each other in style or technique. In situations like that, complexity is naturally going to arise (though certainly, we should fight it as much as possible). I think the best thing colleges can do to help students learn pointers is to to use good demonstrations, combined with projects that require pointer use. One difficult project will do more for pointer understanding than a thousand demonstrations. Demonstrations can get you a shallow understanding, but to deeply grasp pointers, you have to really use them.
If your colleague lacks experience writing tests maybe he or she is having difficulty testing beyond simple situations, and that is manifesting itself as inadequate testing. Here's what I would try: - Spend some time and share testing techniques, like dependency injection, looking for edge cases, and so on with your colleague. - Offer to answer questions about testing. - Do code reviews of tests for a while. Ask your colleague to review changes of yours that are exemplary of good testing. Look at their comments to see if they're really reading and understanding your test code. - If there are books that fit particularly well with your team's testing philosophy give him or her a copy. It might help if your code review feedback or discussions reference the book so he or she has a thread to pick up and follow. I wouldn't especially emphasize the shame/guilt factor. It is worth pointing out that testing is a widely adopted, good practice and that writing and maintaining good tests is a professional courtesy so your team mates don't need to spend their weekends at work, but I wouldn't belabor those points. If you really need to "get tough" then institute an impartial system; nobody likes to feel like they're being singled out. For example your team might require code to maintain a certain level of test coverage (able to be gamed, but at least able to be automated); require new code to have tests; require reviewers to consider the quality of tests when doing code reviews; and so on. Instituting that system should come from team consensus. If you moderate the discussion carefully you might uncover other underlying reasons your colleague's testing isn't what you expect.
The comment by Rory that the proxy would have to use a self-signed cert if not stricltly true. The proxy could be implemented to generate a new cert for each new SSL host it is asked to deal with and sign it with a common root cert. In the OP's scenario of a corportate environment the common signing cert can rather easily be installed as a trusted CA on the client machines and they will gladly accept these "faked" SSL certs for the traffic being proxied as there will be no hostname mismatch. In fact this is exactly how software such as the [Charles Web Debugging Proxy][1] allow for inspection of SSL traffic without causing security errors in the browser, etc. [1]: http://www.charlesproxy.com/
I don't mean this to sound snarky, but it doesn't matter. Seriously. Look at the things that are important: your project, your code, your job, your personal life. None of them are going to have their success rest on whether or not you use the "this" keyword to qualify access to fields. The this keyword will not help you ship on time. It's not going to reduce bugs, it's not going to have any appreciable effect on code quality or maintainability. It's not going to get you a raise, or allow you to spend less time at the office. It's really just a style issue. If you like "this", then use it. If you don't, then don't. If you need it to get correct semantics then use it. The truth is, every programmer has his own unique programing style. That style reflects that particular programmer's notions of what the "most aesthetically pleasing code" should look like. By definition, any other programmer who reads your code is going to have a different programing style. That means their is always going to be something you did that the other guy doesn't like, or would have done differently. At some point some guy is going to read your code and grumble about something. I wouldn't fret over it. I would just make sure the code is as aesthetically pleasing as possible according to your own tastes. If you ask 10 programmers how to format code, you are going to get about 15 different opinions. A better thing to focus on is how the code is factored. Are things abstracted right? Did I pick meaningful names for things? Is their a lot of code duplication? Are their ways I can simplify stuff? Getting those things right, I think, will have the greatest positive impact on your project, your code, your job, and your life. Coincidentally, it will probably also cause the other guy to grumble the least. If your code works, is easy to ready, and is well factored, the other guy isn't going to be scrutinizing how you initialize fields. He's just going to use your code, marvel at it's greatness, and then move on to something else.
I don't mean this to sound snarky, but it doesn't matter. Seriously. Look at the things that are important: your project, your code, your job, your personal life. None of them are going to have their success rest on whether or not you use the "this" keyword to qualify access to fields. The this keyword will not help you ship on time. It's not going to reduce bugs, it's not going to have any appreciable effect on code quality or maintainability. It's not going to get you a raise, or allow you to spend less time at the office. It's really just a style issue. If you like "this", then use it. If you don't, then don't. If you need it to get correct semantics then use it. The truth is, every programmer has his own unique programing style. That style reflects that particular programmer's notions of what the "most aesthetically pleasing code" should look like. By definition, any other programmer who reads your code is going to have a different programing style. That means their is always going to be something you did that the other guy doesn't like, or would have done differently. At some point some guy is going to read your code and grumble about something. I wouldn't fret over it. I would just make sure the code is as aesthetically pleasing as possible according to your own tastes. If you ask 10 programmers how to format code, you are going to get about 15 different opinions. A better thing to focus on is how the code is factored. Are things abstracted right? Did I pick meaningful names for things? Is their a lot of code duplication? Are their ways I can simplify stuff? Getting those things right, I think, will have the greatest positive impact on your project, your code, your job, and your life. Coincidentally, it will probably also cause the other guy to grumble the least. If your code works, is easy to read, and is well factored, the other guy isn't going to be scrutinizing how you initialize fields. He's just going to use your code, marvel at it's greatness, and then move on to something else.
Strongly agree that syntactically C# beats Java hands down, so there is really no reason to lament the demise of j#. Now trying to get c# compiling to Java bytecode might be an interesting move as Sun's hotspot jvm is great software. Or, for a bit of fun with what might well become the next generation of Java, how about [Scala on the CLR][1]... [1]: http://www.scala-lang.org/node/168