instruction
stringlengths
0
30k
You may have to generate you own "glyph cache" in texture memory as you go, potentially with some sort of LRU policy to avoid destroying all of the texture memory. Not nearly as easy as your current method, but may be the only way given the number of unicode chars
[Install4J][1]. Not free, but worth it. Give the trial a shot [1]: http://www.ej-technologies.com/products/install4j/overview.html
My favourite "start learning to code" project is the Game **Snakes** or **Tron** because it allows you to start slow (variables to store the current "worm position", arrays to store the worm positions if the worm is longer than one "piece", loops to make the worm move, if/switch to allow the user to change the worm's direction, ...). It also allows to include more and more stuff into the project in the long run, e.g. object oriented programming (one worm is one object with the chance to have two worms at the same time) with inheritance (go from "Snakes" to "Tron" or the other way around, where the worm slightly changes behavior). I'd suggest that you use [Microsoft's XNA][1] to start. In my experience starting to program is much more fun if you can see something on your screen, and XNA makes it really easy to get something moving on the screen. It's quite easy to do little changes and get another look, e.g. by changing colors, so he can see that his actions have an effect -> Impression of success. Success is fun, which is a great motivation to keep on learning. [1]: http://creators.xna.com/
Eclipse does some of this in Java (or PHP with plugins) on its own. Allows you to fold functions and such. I tend to like it. If I know what a function does and I am not working on it, I dont need to look at it.
I agree with @lomaxx, it's more important to be consistent throughout the team than to have the *right* convention. Still, here are several good places to get ideas and guidance for coding conventions: 1. [Practical Guidelines and Best Practices for Microsoft Visual Basic and Visual C#][1] Developers by Francesco Balena is a great book that addresses many of these issues. 2. [IDesign Coding Standards][2] (for C# and for WCF) 3. The .NET Framework [Source Code][3] (in VS2008) [1]: http://www.dotnet2themax.com/PracticalGuidelines.aspx [2]: http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=0&tabid=1 [3]: http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx
Yes your insight is correct. This is called [dynamic programming][1]. It is a common memory runtime trade-off. (By the way, there are a few other way to compute fibonacci faster.) @John: I don't think it has anything to do with do with hash. [1]: http://en.wikipedia.org/wiki/Dynamic_programming
Yes your insight is correct. This is called [dynamic programming][1]. It is usually a common memory runtime trade-off. In the case of fibo, you don't even need to cache everything : int fibo(int n) { if (n == 0 ) return 1; if (n == 1 ) return 1; int p = fibo(0); int c = fibo(1); int buff = 0; for (int i=1; i < n; ++i) { buff = c; c = p+c; p = buff; }; return c; }; This perform in linear time. But log is actually possible !!! @John: I don't think it has anything to do with do with hash. [1]: http://en.wikipedia.org/wiki/Dynamic_programming
Yes your insight is correct. This is called [dynamic programming][1]. It is usually a common memory runtime trade-off. In the case of fibo, you don't even need to cache everything : int fibo(int n) { if (n == 0 ) return 1; if (n == 1 ) return 1; int p = fibo(0); int c = fibo(1); int buff = 0; for (int i=1; i < n; ++i) { buff = c; c = p+c; p = buff; }; return c; }; This perform in linear time. But log is actually possible !!! Roo's program is linear too, but way slower, and use memory. Now for the linear time algorithm (way way way faster), here is a method : If you know u(n), u(n-1), computing u(n+1), u(n) can be done by applying a matrix: | u(n+1) | = | 1 1 | | u(n) | | u(n) | | 1 0 | | u(n-1) | So that you have : | u(n) | = | 1 1 |^(n-1) | u(1) | | u(n-1) | 1 0 | | u(0) | Computing the exponential of the matrix has a logarithmic complexity. Using the idea : M^(2p) = (M^p) * (M^p) M^(2p+1) = (M^p) * (M^p) * M You can also just diagonalize it (not to difficult), you will find the gold number and its conjugate in its eigen value, and the result will give you an EXACT mathematical formula for u(n). It contains powers of those eigenvalues, so that the complexity will still be logarithmic. @John: I don't think it has anything to do with do with hash. @John2: Still not a map. For fibonacci case, all the keys are contiguous so that a vector is appropriate, once again there are much faster ways to compute fibo sequence, see my code sample over there. [1]: http://en.wikipedia.org/wiki/Dynamic_programming
Yes your insight is correct. This is called [dynamic programming][1]. It is usually a common memory runtime trade-off. In the case of fibo, you don't even need to cache everything : **Here is a linear algorithm O(n)** int fibo(int n) { if (n == 0 ) return 1; if (n == 1 ) return 1; int p = fibo(0); int c = fibo(1); int buff = 0; for (int i=1; i < n; ++i) { buff = c; c = p+c; p = buff; }; return c; }; This perform in linear time. But log is actually possible !!! Roo's program is linear too, but way slower, and use memory. **Here is the log algorithm O(log(n))** Now for the log-time algorithm (way way way faster), here is a method : If you know u(n), u(n-1), computing u(n+1), u(n) can be done by applying a matrix: | u(n+1) | = | 1 1 | | u(n) | | u(n) | | 1 0 | | u(n-1) | So that you have : | u(n) | = | 1 1 |^(n-1) | u(1) | | u(n-1) | 1 0 | | u(0) | Computing the exponential of the matrix has a logarithmic complexity. Using the idea : M^(2p) = (M^p) * (M^p) M^(2p+1) = (M^p) * (M^p) * M You can also just diagonalize it (not to difficult), you will find the gold number and its conjugate in its eigen value, and the result will give you an EXACT mathematical formula for u(n). It contains powers of those eigenvalues, so that the complexity will still be logarithmic. *Fibo is often taken as an example to illustrate Dynamic Programming, but as you see, it is not really pertinent.* @John: I don't think it has anything to do with do with hash. @John2: Still not a map. For fibonacci case, all the keys are contiguous so that a vector is appropriate, once again there are much faster ways to compute fibo sequence, see my code sample over there. [1]: http://en.wikipedia.org/wiki/Dynamic_programming
Well, Vim's generic completion mechanism is surprisingly good, just using Ctrl-N in insert mode. Also, line completion is very handy, using C-x C-l. Also check out this [vim script for perl][1]. [1]: http://www.vim.org/scripts/script.php?script_id=556
I love debugging with the [Multiple startup projects option][1] [1]: http://blogs.msdn.com/saraford/archive/2008/07/28/did-you-know-you-can-start-debugging-multiple-projects-268.aspx
<code>document.write</code> is about as deprecated as they come. Thanks to the wonders of JavaScript, though, you can just assign your own function to the <code>write</code> method of the <code>document</code> object which uses <code>innerHTML</code> on an element of your choosing to append the supplied content.
Vim 7 supports omni completion. For example, I have this in my vimrc autocmd FileType php set omnifunc=phpcomplete#CompletePHP and then, when I press **Ctrl-x Ctrl-o** in Insert mode, I get a dropdown list of autocomplete possibilities. Here's an omnicfunc [for perl](http://www.vim.org/scripts/script.php?script_id=1924). No idea how well it works though.
I believe `places.sqlite` is the one you should be looking into for history (Firefox 3). Here's [a Mozilla wiki entry][1] that has some info on the subject. [1]: https://wiki.mozilla.org/Mozilla2:Unified_Storage
I believe `places.sqlite` is the one you should be looking into for history (Firefox 3). Below are a couple of Mozilla wiki entries that have some info on the subject. - [Mozilla 2: Unified Storage][1] - [Browser History][2] *(see especially section "Database Design" here)* [1]: https://wiki.mozilla.org/Mozilla2:Unified_Storage [2]: https://wiki.mozilla.org/Browser_History
I believe `places.sqlite` is the one you should be looking into for history (Firefox 3). Below are a couple of Mozilla wiki entries that have some info on the subject. - [Mozilla 2: Unified Storage][1] - [Browser History][2] *(see especially section "Database Design" here)* In earlier versions of Firefox they stored history in a file called `history.dat`, which was encoded in a format called "Mork". [This perl script by Jamie Zawinski][3] can be used to parse Mork files. [1]: https://wiki.mozilla.org/Mozilla2:Unified_Storage [2]: https://wiki.mozilla.org/Browser_History [3]: http://www.jwz.org/hacks/mork.pl
Cntl-N This is explained in the Perl Hacks book, along with how to do Package completion. Highly recommended.
What is the Best Way to Populate a Menu Control on a Master Page
|.net-3.5|menu|master-pages|
Database? Page variables? Enum????? looking for opionions here.
Typically I have always done this using a 3rd party aggregator. The messages are compiled into SMIL, which is the description language for the MMS messages. These are then sent on to the aggregator who will then send them through the MMS gateway of the Network Operator. They are typically charged on a per message basis and the aggregators will buy the messages in a block from the operators. If you are trying to send an MMS message without getting charged then I am not sure how to do this, or if it is possible.
How Do I Test Rails Logging In from the Console?
|ruby|ruby-on-rails|
I was having a heck of a time figuring out how to login and logout using response objects from Rails. The standard blogs were ok, but I finally diagnosed it, and I wanted to record it here. app.get '/' assert_response :success app.get '/auth_only_url' assert_response 302 user = User.find(:user_to_login) app.post '/signin_url', :user_email => user.email, :user_password => '<password in clear>' assert_response 302 app.follow_redirect! assert_response :success app.get '/auth_only_url' assert_response :success Note, the above implies that you redirect after a failed auth request, and also that you redirect after logging in. To ensure that you load the fixtures into your test environment DB (which normally occurs during rake test), make sure you execute the following: rake db:fixtures:load RAILS_ENV=test Also, haven't figured out why the default URL always lists as 'http://www.example.com/' ... any thoughts there?
I was having a heck of a time figuring out how to login and logout using response objects from Rails. The standard blogs were ok, but I finally diagnosed it, and I wanted to record it here. app.get '/' assert_response :success app.get '/auth_only_url' assert_response 302 user = User.find(:user_to_login) app.post '/signin_url', :user_email => user.email, :user_password => '<password in clear>' assert_response 302 app.follow_redirect! assert_response :success app.get '/auth_only_url' assert_response :success Note, the above implies that you redirect after a failed auth request, and also that you redirect after logging in. To ensure that you load the fixtures into your test environment DB (which normally occurs during rake test), make sure you execute the following: rake db:fixtures:load RAILS_ENV=test (From Patrick Richie) The default URL will appear to be 'www.example.com', as this default host as set in ActionController::Integration::Session ActionController::Integration::Session.new.host=> "www.example.com" It is set in actionpack/lib/action_controller/integration.rb#75 To change it in the integration test, do the following: session = open_session do |s| s.host = 'my-example-host.com' end
How to export findbugs results from Eclipse findbugs plugin?
|java|eclipse-plugin|findbugs|
I have findbugs plugin for eclipse which when run on my project will show results in Bugs explorer clubbed by the type of bug. I need to be able to do two things: - Export all these to excel sheet - Find out the bugs reported in a set of files (and be able to do it recursively w/o running for whole project and exporting and finding out the classes to be modified. Any suggestions? FYI, I am using MyEclipse v 6.0.1 and FindBugs 1.3.4
You should be able to go : Class Animal<SpeciesType, OrderType> where SpeciesType : Species where OrderType : Order
I do not think you can use the Management Studio GUI to update XML-columns without writing the UPDATE-command yourself. One way you could let users update xml-data is to write a simple .net based program (winforms or asp.net) and then select/update the data from there. This way you can also sanitize the data and easily validate it against any given schema before inserting/updating the information.
How do I create tri-state checkboxes with a TreeView control in .NET?
|vb.net|
I have a treeview control with checkboxes turned on. Because the treeview control has nested nodes, I need the checkboxes to be able to have some sort of tri-mode selection. I can't find a way to do this (I can only have the checkboxes fully checked or unchecked).
|.net|
I have a treeview control in a Windows Forms project that has checkboxes turned on. Because the treeview control has nested nodes, I need the checkboxes to be able to have some sort of tri-mode selection. I can't find a way to do this (I can only have the checkboxes fully checked or unchecked).
Apache rewrite based on subdomain
|apache|mod-rewrite|
Im trying to redirect requests for a wildcard domain to a sub-directory. ie. `something.blah.domain.com` --> `blah.domain.com/something` I dont know how to get the subdomain name to use in the rewrite rule.
Im trying to redirect requests for a wildcard domain to a sub-directory. ie. `something.blah.domain.com` --> `blah.domain.com/something` I dont know how to get the subdomain name to use in the rewrite rule. **Final Solution:** RewriteCond %{HTTP_HOST} !^blah\.domain\.com RewriteCond %{HTTP_HOST} ^([^.]+) RewriteRule ^(.*) /%1/$1 [L]
Im trying to redirect requests for a wildcard domain to a sub-directory. ie. `something.blah.domain.com` --> `blah.domain.com/something` I dont know how to get the subdomain name to use in the rewrite rule. **Final Solution:** RewriteCond %{HTTP_HOST} !^blah\.domain\.com RewriteCond %{HTTP_HOST} ^([^.]+) RewriteRule ^(.*) /%1/$1 [L] Or as pointed out by pilif RewriteCond %{HTTP_HOST} ^([^.]+)\.media\.xnet\.tk$
It's not so much that structs are "immutable." The real underlying issue is that structs are a Value type, not a Reference type. So when you pull out a "reference" to the struct from the list, it is creating a new copy of the entire struct. So any changes you make on it are changing the copy, not the original version in the list. Like Andrew states, you have to replace the entire struct. As that point though I think you have to ask yourself why you are using a struct in the first place (instead of a class). Make sure you aren't doing it around premature optimization concerns.
Pass the :domain on delete as well. Here's the source of that method: # Removes the cookie on the client machine by setting the value to an empty string # and setting its expiration date into the past. Like []=, you can pass in an options # hash to delete cookies with extra data such as a +path+. def delete(name, options = {}) options.stringify_keys! set_cookie(options.merge("name" => name.to_s, "value" => "", "expires" => Time.at(0))) end As you can see, it just sets a cookie with the name you gave, set to expire in 1969, and with no contents. But it does merge in any other options you give, so you can do: cookies.delete :foo, :domain => '.acme.com' And you're set.
Packaging Java apps for the Windows/Linux desktop.
|java|windows|executable|swt|
I am writing an application in Java for the desktop using the Eclipse SWT library for GUI rendering. I think SWT helps Java get over the biggest hurdle for acceptance on the desktop: namely providing a Java application with a consistent, responsive interface that looks like that belonging to any other app on your desktop. However, I feel that packaging an application is still an issue. OS X natively provides an easy mechanism for wrapping Java apps in native application bundles, but producing an app for Windows/Linux that doesn't require the user to run an ugly batch file or click on a .jar is still a hassle. Possibly that's not such an issue on Linux, where the user is likely to be a little more tech-savvy, but on Windows I'd like to have a regular .exe for him/her to run. Has anyone had any experience with any of the .exe generation tools for Java that are out there? I've tried JSmooth but had various issues with it. Is there a better solution before I crack out Visual Studio and roll my own?
|java|windows|swt|executable|
I am writing an application in Java for the desktop using the Eclipse SWT library for GUI rendering. I think SWT helps Java get over the biggest hurdle for acceptance on the desktop: namely providing a Java application with a consistent, responsive interface that looks like that belonging to any other app on your desktop. However, I feel that packaging an application is still an issue. OS X natively provides an easy mechanism for wrapping Java apps in native application bundles, but producing an app for Windows/Linux that doesn't require the user to run an ugly batch file or click on a .jar is still a hassle. Possibly that's not such an issue on Linux, where the user is likely to be a little more tech-savvy, but on Windows I'd like to have a regular .exe for him/her to run. Has anyone had any experience with any of the .exe generation tools for Java that are out there? I've tried JSmooth but had various issues with it. Is there a better solution before I crack out Visual Studio and roll my own? **Edit:** I should perhaps mention that I am unable to spend a lot of money on a commercial solution.
@[AnotherHowie][1], I thought the whole preprocessing could be done with sort and uniq. The problem is that the OP's data seems to be comma delimited and (Solaris 8's) uniq doesn't allow you any way specify the record separator, so there wasn't a super clean way to do the preprocessing using standard unix tools. I don't think it would be any faster so I'm not going to look up the exact options, but you could do something like: cut -d, -f8 <infile.txt | sort | uniq -d | xargs -i grep {} infile.txt >outfile.txt That's not very good because it executes grep for every line containing a duplicate key. You could probably massage the uniq output into a single regexp to feed to grep, but the benefit would only be known if the OP posts expected ratio of lines containing suspected duplicate keys to total lines in the file. [1]: http://stackoverflow.com/questions/6475/faster-way-to-find-duplicates-conditioned-by-time#7210
I went through the same and found that all of the free options weren't very good. Looks like you'll be writing your own. I'd be interested to see if someone has a free/cheap option that works
Yes your insight is correct. This is called [dynamic programming][1]. It is usually a common memory runtime trade-off. In the case of fibo, you don't even need to cache everything : **Here is a linear algorithm O(n)** int fibo(int n) { if (n == 0 ) return 1; if (n == 1 ) return 1; int p = fibo(0); int c = fibo(1); int buff = 0; for (int i=1; i < n; ++i) { buff = c; c = p+c; p = buff; }; return c; }; This perform in linear time. But log is actually possible !!! Roo's program is linear too, but way slower, and use memory. **Here is the log algorithm O(log(n))** Now for the log-time algorithm (way way way faster), here is a method : If you know u(n), u(n-1), computing u(n+1), u(n) can be done by applying a matrix: | u(n+1) | = | 1 1 | | u(n) | | u(n) | | 1 0 | | u(n-1) | So that you have : | u(n) | = | 1 1 |^(n-1) | u(1) | | u(n-1) | 1 0 | | u(0) | Computing the exponential of the matrix has a logarithmic complexity. Using the idea : M^(2p) = (M^p) * (M^p) M^(2p+1) = (M^p) * (M^p) * M You can also just diagonalize it (not to difficult), you will find the gold number and its conjugate in its eigen value, and the result will give you an EXACT mathematical formula for u(n). It contains powers of those eigenvalues, so that the complexity will still be logarithmic. *Fibo is often taken as an example to illustrate Dynamic Programming, but as you see, it is not really pertinent.* @John: I don't think it has anything to do with do with hash. @John2: A map is a bit general don't you think? For Fibonacci case, all the keys are contiguous so that a vector is appropriate, once again there are much faster ways to compute fibo sequence, see my code sample over there. [1]: http://en.wikipedia.org/wiki/Dynamic_programming
Yes your insight is correct. This is called [dynamic programming][1]. It is usually a common memory runtime trade-off. In the case of fibo, you don't even need to cache everything : **Here is a linear algorithm O(n)** in OCaml: let rec fibo n = let rec aux = fun | 0 -> (1,1) | n -> let (cur, prec) = aux (n-1) in (cur+prec, cur) let (cur,prec) = aux n in prec;; in C++: int fibo(int n) { if (n == 0 ) return 1; if (n == 1 ) return 1; int p = fibo(0); int c = fibo(1); int buff = 0; for (int i=1; i < n; ++i) { buff = c; c = p+c; p = buff; }; return c; }; This perform in linear time. But log is actually possible !!! Roo's program is linear too, but way slower, and use memory. **Here is the log algorithm O(log(n))** Now for the log-time algorithm (way way way faster), here is a method : If you know u(n), u(n-1), computing u(n+1), u(n) can be done by applying a matrix: | u(n+1) | = | 1 1 | | u(n) | | u(n) | | 1 0 | | u(n-1) | So that you have : | u(n) | = | 1 1 |^(n-1) | u(1) | | u(n-1) | 1 0 | | u(0) | Computing the exponential of the matrix has a logarithmic complexity. Using the idea : M^(2p) = (M^p) * (M^p) M^(2p+1) = (M^p) * (M^p) * M You can also just diagonalize it (not to difficult), you will find the gold number and its conjugate in its eigen value, and the result will give you an EXACT mathematical formula for u(n). It contains powers of those eigenvalues, so that the complexity will still be logarithmic. *Fibo is often taken as an example to illustrate Dynamic Programming, but as you see, it is not really pertinent.* @John: I don't think it has anything to do with do with hash. @John2: A map is a bit general don't you think? For Fibonacci case, all the keys are contiguous so that a vector is appropriate, once again there are much faster ways to compute fibo sequence, see my code sample over there. [1]: http://en.wikipedia.org/wiki/Dynamic_programming
You could use DOS? DIR /s/b > Files.txt
Normally, you would create a new Rails app using rails ProjectName To use MySQL, use rails -d mysql ProjectName
If you are creating a new rails application you can set the database using the -d switch like this: rails -d mysql myapp Its always easy to switch your database later though, and using sqlite really is easier if you are developing on a Mac.
Why not just use SQL Management Studio to create a complete script of your database and the objects?
To make the things a little more clear: 1. Yes, I know that using HTTP_REFERER is completely unreliable and somewhat childish but I'm pretty sure that the people that learned (from me maybe?) to make automations with Excel VBA will not know how to subvert a HTTP_REFERER within the time span to have the final solution. 2. I don't have access/privilege to modify the application code. Politics. Do you believe that? So, I must to wait until the rights holder make the changes I requested. 3. From previous experiences, I know that the requested changes will take two month to get in Production. No, tossing them Agile Methodologies Books in their heads didn't improve anything. 4. This is an intranet app. So I don't have a lot of youngsters trying to undermine my prestige. But I'm young enough as to try to undermine the prestige of "a very fancy global consultancy services that comes from India" but where, curiously, there are not a single indian working there. So far, the best answer comes from "Michel de Mare": block users based on their IPs. Well, that I did yesterday. Today I wanted to make something more generic because I have a lot of kangaroo users (jumping from an Ip address to another) because they use VPN or DHCP.
Searching directories for tons of files?
|c#|filemanagement|directory|
I'm using MSVE, and I have my own tiles I'm displaying in layers on top. Problem is, there's a ton of them, and they're on a network server. In certain directories, there are something on the order of 30,000+ files. Initially I called Directory.GetFiles, but once I started testing in a pseudo-real environment, it timed out. What's the best way to programatically list, and iterate through, this many files?
|c#|directory|filemanagement|
I'm using MSVE, and I have my own tiles I'm displaying in layers on top. Problem is, there's a ton of them, and they're on a network server. In certain directories, there are something on the order of 30,000+ files. Initially I called Directory.GetFiles, but once I started testing in a pseudo-real environment, it timed out. What's the best way to programatically list, and iterate through, this many files? Edit: My coworker suggested using the MS indexing service. Has anyone tried this approach, and (how) has it worked?
Definitely split them up. That said, stay as far away from the Indexing Service as you can.
If you already have a rails project, change the adapter in the `config/database.yml` file to `mysql` and make sure you specify a valid username and password, and optionally, a socket: development: adapter: mysql database: db_name_dev username: koploper password: host: localhost socket: /tmp/mysql.sock
I think that your example would work just as well if you used a &lt;div&gt; instead of a &lt;table&gt;. The only difference is that the text in the &lt;table&gt; is also centered. If you want that too, just add the <tt>text-align: center;</tt> rule. Another thing to keep in mind is that the &lt;div&gt; will by default fill up all the available horizontal space. Put a border on it if you aren't sure where it starts and ends.
I would solve it using the technique below. The example expect an *article* table with an *id* on each row. Delete article where id not in (select top 1000 id from article) Edit: Too slow to answer my own question ...
Automatic Timeout Web Client Use
|c#|asp.net|
One of the problems I have come accross having complext tasks on the browser is with automatic timeouts. Currently our site has a sliding expiration of 30 minutes. Normally this isn't a problem because we use asp.net and most of the time the users update one or two fields and then submit the form. This obviously keeps the session active. I have struggled with how to handle this with significantly more complex forms/user interaction where there are few if no round trips to the server. Now users can view reports, type emails etc. on our site, and I am struggling with how to keep their session active while they're actually using browser but they are not actively posting information back. I would dispense with the sliding expiration, but it's a requirement, so I am stuck with it. Most of our users are outside of the organization, so I can't use any form of SSO. Does anyone have an elegant solution (I'll even go for an ugly one if it works), or am I out of luck?
Take a look at this code from the Mono project http://tirania.org/blog/archive/2008/Aug-26.html I played with it some the other day. It does a lot of command line editingy, but I don't think it does line completion.
You can set an EVENT in your parameter file (plain text or spfile) to force Oracle to dump a detailed trace file in the user_dump_dest, the object name might be in there, if not the SQL should be. EVENT="942 trace name errorstack level 12" If you are using a plain text file you need to keep all your EVENT settings on consecutive lines. Not sure how that applied to spfile.
One solution is to serialize the inner object to a string and then load the string into a XmlDocument where you can find the XmlNode representing your data and attach it to the outer object. XmlSerializer xser1 = new XmlSerializer(typeof(Config)); XmlSerializer xser2 = new XmlSerializer(typeof(MyConfig)); MyConfig myConfig = new MyConfig(); myConfig.data = "My special data"; StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); XmlWriter xw = new XmlTextWriter(sw); xser2.Serialize(xw, myConfig); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); Config config = new Config(); config.data = "some new info"; config.element = doc.LastChild; xser1.Serialize(fs, config); However, this solution is cumbersome and I would hope there is a better way, but it resolves my problem for now. Now if I could just find the mythical XmlNodeWriter referred to on several blogs!
You could try using [find][1]. [1]: http://www.scala-lang.org/docu/files/api/scala/List.html#find((A)%3D%3EBoolean)
IF the menu is dynamic _per-user_ then you'll have to hit the database for each user. From then on I would probably store it in session to avoid future round-trips to the database. If it's dynamic, but the entire site sees the same items, then put it in the database and cache the results
In my experience not all browsers handle this properly. I'm not really sure why (or which browsers) but I've mistakenly sent links like this to clients on occasion and they've often come back confused. I suspect their browser prompts them to download the file instead of displaying it properly.
[http://codex.wordpress.org/Function_Reference/wp_schedule_event][1] [1]: http://codex.wordpress.org/Function_Reference/wp_schedule_event
Binding to a Sitemap is certainly the easiest.
That's an interesting question, there are lots of ways to approach it. You could load the menu structure from XML, that's the way the built-in ASP.NET navigation controls/"sitemap" setup works. This is probably a good choice overall, and there is reasonably good tooling for it in Visual Studio. If it's a dynamic menu that needs to change a lot, getting the items from a database could be a good idea, but you would definitely want to cache them, so the DB doesn't get hit on every page render.
I suspect one of the reasons javascript is becoming more popular is that it's more easy to retrofit into an existing application.
[This post][1] earlier discussed different approaches for SMS and might be helpful for you. [1]: http://stackoverflow.com/questions/53019/what-kind-of-technologies-are-available-for-sending-text-messages#53067
http://www.isecpartners.com/files/web-session-management.pdf A 19 page white paper on "Secure Session Management with Cookies for Web Applications" They cover lots of security issues that I haven't seen all in one spot before. It's worth a read.
Using jQuery to beautify someone else's html
|html|jquery|
I have a third-party app that creates HTML-based reports that I need to display. I have *some* control over how they look, but in general it's pretty primitive. I *can* inject some javascript, though. I'd like to try to inject some jQuery goodness into it to tidy it up some. One specific thing I would like to do is to take a table (an actual HTML &lt;table&gt;) that always contains one row and a variable number of columns and magically convert that into a tabbed view where the contents (always one &lt;div&gt; that I can supply an ID if necessary) of each original table cell represents a sheet in the tabbed view. I haven't found any good (read: simple) examples of re-parenting items like this, so I'm not sure where to begin. Can someone provide some hints on how I might try this?
Here's another one that has bit me from time to time. When you are working on FORTRAN code make sure you skip all six initial columns. Every once and a while, I'll only get the code indented five spaces and nothing works. At first glance everything seems okay and then I finally realize that all the lines are starting in column 6 instead of column 7. For anyone not familiar with FORTRAN, the first 5 columns are for line numbers (=labels), the 6th column is for a continuation character in case you have a line longer than 80 characters (just put something here and the compiler knows that this line is actually part of the one before it) and code always starts in column 7.
Yes your insight is correct. This is called [dynamic programming][1]. It is usually a common memory runtime trade-off. In the case of fibo, you don't even need to cache everything : **Here is a linear algorithm O(n)** in OCaml: let rec fibo n = let rec aux = fun | 0 -> (1,1) | n -> let (cur, prec) = aux (n-1) in (cur+prec, cur) let (cur,prec) = aux n in prec;; in C++: int fibo(int n) { if (n == 0 ) return 1; if (n == 1 ) return 1; int p = fibo(0); int c = fibo(1); int buff = 0; for (int i=1; i < n; ++i) { buff = c; c = p+c; p = buff; }; return c; }; This perform in linear time. But log is actually possible !!! Roo's program is linear too, but way slower, and use memory. **Here is the log algorithm O(log(n))** Now for the log-time algorithm (way way way faster), here is a method : If you know u(n), u(n-1), computing u(n+1), u(n) can be done by applying a matrix: | u(n+1) | = | 1 1 | | u(n) | | u(n) | | 1 0 | | u(n-1) | So that you have : | u(n) | = | 1 1 |^(n-1) | u(1) | = | 1 1 |^(n-1) | 1 | | u(n-1) | | 1 0 | | u(0) | | 1 0 | | 1 | Computing the exponential of the matrix has a logarithmic complexity. Just implement recursively the idea : M^(0) = Id M^(2p+1) = (M^2p) * M M^(2p) = (M^p) * (M^p) // of course don't compute M^p twice here. You can also just diagonalize it (not to difficult), you will find the gold number and its conjugate in its eigenvalue, and the result will give you an EXACT mathematical formula for u(n). It contains powers of those eigenvalues, so that the complexity will still be logarithmic. *Fibo is often taken as an example to illustrate Dynamic Programming, but as you see, it is not really pertinent.* @John: I don't think it has anything to do with do with hash. @John2: A map is a bit general don't you think? For Fibonacci case, all the keys are contiguous so that a vector is appropriate, once again there are much faster ways to compute fibo sequence, see my code sample over there. [1]: http://en.wikipedia.org/wiki/Dynamic_programming
Yes your insight is correct. This is called [dynamic programming][1]. It is usually a common memory runtime trade-off. In the case of fibo, you don't even need to cache everything : **Pure memorization** Since the author is asking for a general sample of code I write here what would be a general application of memorization on this problem. in C++ template <class A, class R> // arg result class DynamicFunction { public: R compute(const A& arg); protected: virtual R computeImpl_(const A& arg) = 0; private: map<A,R> cache; }; R DynamicFunction<A,R>::compute(const A& arg) { map<A,R>::const_iterator itres = cache.find(A); if (itres != cache.end()) { return *itres; } else { R res = computeImpl_(arg); map[arg] = res; return res; }; }; **Here is a linear algorithm O(n)** in OCaml: let rec fibo n = let rec aux = fun | 0 -> (1,1) | n -> let (cur, prec) = aux (n-1) in (cur+prec, cur) let (cur,prec) = aux n in prec;; in C++: int fibo(int n) { if (n == 0 ) return 1; if (n == 1 ) return 1; int p = fibo(0); int c = fibo(1); int buff = 0; for (int i=1; i < n; ++i) { buff = c; c = p+c; p = buff; }; return c; }; This perform in linear time. But log is actually possible !!! Roo's program is linear too, but way slower, and use memory. **Here is the log algorithm O(log(n))** Now for the log-time algorithm (way way way faster), here is a method : If you know u(n), u(n-1), computing u(n+1), u(n) can be done by applying a matrix: | u(n+1) | = | 1 1 | | u(n) | | u(n) | | 1 0 | | u(n-1) | So that you have : | u(n) | = | 1 1 |^(n-1) | u(1) | = | 1 1 |^(n-1) | 1 | | u(n-1) | | 1 0 | | u(0) | | 1 0 | | 1 | Computing the exponential of the matrix has a logarithmic complexity. Just implement recursively the idea : M^(0) = Id M^(2p+1) = (M^2p) * M M^(2p) = (M^p) * (M^p) // of course don't compute M^p twice here. You can also just diagonalize it (not to difficult), you will find the gold number and its conjugate in its eigenvalue, and the result will give you an EXACT mathematical formula for u(n). It contains powers of those eigenvalues, so that the complexity will still be logarithmic. *Fibo is often taken as an example to illustrate Dynamic Programming, but as you see, it is not really pertinent.* @John: I don't think it has anything to do with do with hash. @John2: A map is a bit general don't you think? For Fibonacci case, all the keys are contiguous so that a vector is appropriate, once again there are much faster ways to compute fibo sequence, see my code sample over there. [1]: http://en.wikipedia.org/wiki/Dynamic_programming
You can stream FLV videos using a simple player like [JW FLV Media Player][1]. It supports several streaming methods, playlists etc. It's actively developed, and I have found it to be the best solution for streaming flash video. [1]: http://www.jeroenwijering.com/?item=JW_FLV_Player
This is probably a bit deceptive example, since address is a bit non-normalized in this case. It is a reasonable trade-off, however since address fields are difficult to normalize. If you make the line breaks carry important information, you're un-normalizing and making the post office interpret the meaning of the line break. I would say that normally this is not a big problem, but in this case I think the Line tag is most correct since it explicitly shows that you don't actually interpret what the lines may mean in different cultures. (Remember that most forms for entering an address has zip code etc, and address line 1 and 2.) The awkwardness of having the line tag comes with normal XML, and has been much debated at coding horror. http://www.codinghorror.com/blog/archives/001139.html
Take a look at ISO 11179-5: Naming and identification principles You can get it here: [http://metadata-standards.org/11179/#11179-5][1] I blogged about it a while back here: [ISO-11179 Naming Conventions][2] [1]: http://metadata-standards.org/11179/#11179-5 [2]: http://sqlservercode.blogspot.com/2006/11/iso-11179-naming-conventions.html
9 out of 10 times, code folding means that you have failed to use the <a href="http://en.wikipedia.org/wiki/Separation_of_concerns">SoC principle</a> for what its worth.<br /> I more or less feel the same thing about partial classes. If you have a piece of code you think is too big you need to chop it up in manageable (and reusable) parts, not hide or split it up.<br />It will bite you the next time someone needs to change it, and cannot see the logic hidden in a 250 line monster of a method.<br /> <br /> Whenever you can, pull some code out of the main class, and into a helper or factory class. <br /> foreach (var item in Items) { //.. 100 lines of validation and data logic.. } is not as readable as foreach (var item in Items) { if (ValidatorClass.Validate(item)) RepositoryClass.Update(item); } <br /> <br /> My $0.02 anyways.
If you choose to throw a NPE and you are using the argument in your method, it might be redundant and expensive to explicitly check for a null. I think the VM already does that for you.
I use [RSS Bandit][1] (for Windows) to stay up to date with my RSS feeds/Blogs. There are [lots of other RSS aggregator applications][2], though. If you don't want another "big" application, but have Windows Vista, you could also choose to make Internet Explorer monitor the RSS feed and use the Feed sidebar application (called "Feedschlagzeilen in German version, not sure about the English one) that comes with Vista to show the latest headlines. [1]: http://www.rss-bandit.com/ [2]: http://en.wikipedia.org/wiki/List_of_feed_aggregators
change visibility of asp.net label with javascript
|asp.net|javascript|
Mod-Rewrite loading files behind the DocumentRoot
|mod-rewrite|.htaccess|
I'm using htaccess and mod_rewrite to point to files that reside behide the DocumentRoot. My folder structure looks like this: <pre> home/ webroot/ other_files/ </pre> I have a <code>.htaccess</code> file in webroot with the following: <pre> RewriteEngine on RewriteRule ^(.*)$ /home/other_files/$1 </pre> If I try and access http://mysite.com/file.html I am receive the following error: <pre>The requested URL /home/other_files/file.html was not found on this server.</pre> Is it even possible to load files that are behind the DocumentRoot? If so, can someone point me in the right direction? Thanks in advance.
Add a second (empty) table immediately after the first. Page break after that.
Another option is to use a tool such as [ResourceHacker][1]. It handles way more than just icons as well. Cheers! [1]: http://www.angusj.com/resourcehacker/
I don't grok the WPF command pattern