instruction stringlengths 0 30k ⌀ |
|---|
@Jon Limjap: Unfortunately, this tells you the .NET CLR (runtime library) version, *not* the version of the .NET Framework. These two version numbers are not always the same; in particular, the .NET Framework 3.0 and 3.5 both use the .NET CLR 2.0. So the OP may indeed have only .NET 2.0 SP1, as the Environment.Version indicates, or he may also have the .NET 3.5 SP1 which he is looking for. |
What does the generated Javascript look like?
Sounds (at first glance) like it's not being escaped. |
What steps can I give a windows user to make a given file writeable |
|windows|filesystems| |
Imagine we have a program trying to write to a particular file, but failing.
On the Windows platform, what are the possible things which might be causing the file to be un-writable, and what steps could be suggested to an end user/administrator to fix it. |
|windows|filesystems| |
Imagine we have a program trying to write to a particular file, but failing.
On the Windows platform, what are the possible things which might be causing the file to be un-writable, and what steps could be suggested to an end user/administrator to fix it.
----------
Please include steps which might require administrator permissions (obviously users may not be administrators, but for this question, let's assume they are (or can become) administrators.
Also, I'm not real familiar with how permissions are calculated in windows - Does the user need write access to each directory up the tree, or anything like that? |
For this to work, you'd have to detail how you would want to find all cycles, apparently without any iterative constructs, because that is a non-trivial task. I'm not sure that's possible. If you really want to find a MST algorithm that doesn't use iterative constructs, take a look at [Prim's][1] or [Kruskal's][2] algorithm and see if you could modify those to suit your needs.
Also, is recursion barred in this theoretical architecture? If so, it might actually be impossible to find a MST on a graph, because you'd have no means whatsoever of inspecting every vertex/edge on the graph.
[1]: http://en.wikipedia.org/wiki/Prim%27s_algorithm
[2]: http://en.wikipedia.org/wiki/Kruskal%27s_algorithm |
I'm looking for a tool ($, free, open source; I don't care) that will allow me to view not just the memory statistics for a .NET program, but also the object hierarchy. I'd really like to be able to drill down each thourgh each object and view it's foot print, as well as all the object's it references.
I've looked at things like Ants Profiler from RedGate, but it's not quite what I want: I can't view specific instances.
EDIT:
I've used the .NET Memory Profiler (the one that ships with visual studio, and the one that used to be part of the SDK (?))before, and while it's really good (and shows views most other don't), what I'm really after is being able to drill down through my object hierarchy, viewing each object instance. |
Good Featurs for an ORM |
|c#|orm| |
I'm currently working on putting together a fairly simple ORM tool to serve as a framework for various web projects for a client. Most of the projects are internal and will not require massive amounts of concurrency and all will go against SQL Server. I've suggested that they go with ORM tools like SubSonic, NHibernate, and a number of other open source projects out there, but for maintainability and flexibility reasons they want to create something custom. So my question is this: What are some features that I should make sure to include in this ORM tool? BTW, I'll be using MyGeneration to do the code generation templates. |
Good Features for an ORM |
TFS is great, if you don't need non-developers, to get to pm stuff.
Our helpdesk needs to be involved in the process, and it just wasn't cutting it.
Also the build management in tfs 2005 at least, is attrotious, and it can't even build vs 2008 slns. I really don't like that my source control choice, affects my deployment choices, this is why my team is not an svn shop. |
If it's short, I think you're better off re-writing the code in java. Downloading one 50Mb runtime is bad enough. |
Take a look at [Sourcegear DiffMerge][1]. DiffMerge is the compare and merge tool from their Vault and Fortress products, but they make it available for free as a standalone tool.
[1]: http://www.sourcegear.com/diffmerge/ |
I would rewrite it if it's not too much trouble.
The web service would work, but it seems like that would be a lot of overhead just to reuse a little code.
|
[Araxis Merge][1] is expensive, but great. Handles 3 way merges on files or folders really well. I find the way it displays diffs much more helpful than Windiff or P4's tool.
[1]: http://www.araxis.com/merge/index.html |
Another way to do it is to use `urllib2` module to parse some other page's whois service (many sites like that exist). But that seems like even more of a hack that what you do now, and would give you a dependency on whatever whois site you chose, which is bad.
I hate to say it, but unless you want to re-implement `whois` in your program (which would be re-inventing the wheel), running `whois` on the OS and parsing the output (ie what you are doing now) seems like the right way to do it. |
How do I add existing comments to RDoc in Ruby? |
|ruby| |
I've got all these comments that I want to make into 'RDoc comments' so they can be formatted appropriately and viewed using 'Ri.' Can anyone get me started on understanding how to use RDoc? |
|ruby|rdoc| |
What extra bits? They are going from 6 to 4.
EDIT: Whoops! I'm an idiot. This is kinda like a 2nd grade multiplication table. They strip the outer bits off of the 6-bit block to be encypted, and leave the middle 4. Just like a table for an arithmatic operation, they go down one side, and find the outer bit sequence, then across the top and find the middle ones. To answer your question, it could, but this s-box is just set up to do it the way it does. Its arbitrary. |
What extra bits? They are going from 6 to 4.
EDIT: Whoops! I'm an idiot. This is kinda like a 2nd grade multiplication table. They strip the outer bits off of the 6-bit block to be encypted, and leave the middle 4. Just like a table for an arithmatic operation, they go down one side, and find the outer bit sequence, then across the top and find the middle ones. To answer your question, it could input and output the same number of bits, but this s-box is just set up to do it the way it does. Its arbitrary. |
The reference you have listed for Ruby is for Ruby on Rails. While still ruby deep down, it is definitely not a place to start for people wanting to learn Ruby.
For Ruby tutorials, I would suggest [Why's (Poignant) Guide to Ruby][1] as a great starting point for anyone interested in the language.
If you would want to get into more detail, I would recommend the book [Programming Ruby][2], which has become the standard for all things Ruby. The third edition is currently being written, highlighting Ruby 1.9 features, so I would hold off for a while if anyone is considering buying this book.
[1]: http://poignantguide.net/ruby/
[2]: http://www.pragprog.com/titles/ruby/programming-ruby |
Try using a hash, n is the key and its corresponding Fibonacci number is the value. |
Try using a map, n is the key and its corresponding Fibonacci number is the value.
@Paul
Thanks for the info. I didn't know that. From the [Wikipedia link][1] you mentioned:
> This technique of saving values that
> have already been calculated is called
> memoization
[1]: http://en.wikipedia.org/wiki/Dynamic_programming |
Try using a map, n is the key and its corresponding Fibonacci number is the value.
@Paul
Thanks for the info. I didn't know that. From the [Wikipedia link][1] you mentioned:
> This technique of saving values that
> have already been calculated is called
> memoization
Yeah I already looked at the code (+1). :)
[1]: http://en.wikipedia.org/wiki/Dynamic_programming |
Setting Attributes in Webby Layouts |
|ruby|webby| |
I'm working with [Webby][1] and am looking for some clarification. Can I define attributes like `title` or `author` in my layout?
[1]: http://webby.rubyforge.org "Webby" |
I uploaded it and got an internal error
Premature end of script headers
After much playing around, I found that if I had
import cgi
import cgitb; cgitb.enable()
import MySQLdb
It would give me a much more useful answer and say that it was not installed, you can see it yourself -> [http://woarl.com/db.py][1]
Oddly enough, this would produce an error
import MySQLdb
import cgi
import cgitb; cgitb.enable()
I looked at some of the other files I had up there and it seems that library was one of the ones I had already tried.
[1]: http://woarl.com/db.py |
I uploaded it and got an internal error
Premature end of script headers
After much playing around, I found that if I had
import cgi
import cgitb; cgitb.enable()
import MySQLdb
It would give me a much more useful answer and say that it was not installed, you can see it yourself -> [http://woarl.com/db.py][1]
Oddly enough, this would produce an error
import MySQLdb
import cgi
import cgitb; cgitb.enable()
I looked at some of the other files I had up there and it seems that library was one of the ones I had already tried.
[1]: http://woarl.com/db.py |
It is possible to skip the step of creating the empty database. You can create the new database as part of the restore process.
This is actually the easiest and best way I know of to clone a database. You can eliminate errors by scripting the backup and restore process rather than running it through the SQL Server Management Studio
There are two other options you could explore:
1. Detach the database, copy the .mdf file and re-attach.
2. Use SQL Server Integration Services (SSIS) to copy all the objects over
I suggest sticking with backup and restore and automating if necessary. |
MySQLdb is what I have used before.
If you host is using Python version 2.5 or higher, support for sqlite3 databases is built in (sqlite allows you to have a relational database that is simply a file in your filesystem). But buyer beware, sqlite is not suited for production, so it may depend what you are trying to do with it.
Another option may be to call your host and complain, or change hosts. Honestly these days, any self respecting web host that supports python and mysql ought to have MySQLdb pre installed. |
@ Mark Harrison : SQL Server does not support that syntax (SELECT ... FOR UPDATE). The SQL Server equivalent is the SELECT statement hint UPDLOCK. See [SQL Server Books Online](http://msdn.microsoft.com/en-us/library/ms187373.aspx) for more information. |
You can not do this programatically (in a safe way that is) without creating a new table.
What Enterprise Manager does when you commit a reordering is to create a new table, move the data and then delete the old table and rename the new table to the existing name.
If you want your columns in a particular order (other that the physical) without changing anything physical, you can create a view with columns in any order you like. |
You can not do this programatically (in a safe way that is) without creating a new table.
What Enterprise Manager does when you commit a reordering is to create a new table, move the data and then delete the old table and rename the new table to the existing name.
If you want your columns in a particular order/grouping without altering their physical order, you can create a view which can be whatever you desire. |
What can I do to resolve a "Row not found or changed" Exception in LINQ to SQL on a SQL Server Compact Edition Database? |
|linq-to-sql| |
|.net|linq|linq-to-sql| |
When executing SubmitChanges to the DataContext after updating a couple properties with a LINQ to SQL connection (against SQL Server Compact Edition) I get a "Row not found or changed." ChangeConflictException.
var ctx = new Data.MobileServerDataDataContext(Common.DatabasePath);
var deviceSessionRecord = ctx.Sessions.First(sess => sess.SessionRecId == args.DeviceSessionId);
deviceSessionRecord.IsActive = false;
deviceSessionRecord.Disconnected = DateTime.Now;
ctx.SubmitChanges();
The query generates the following SQL:
UPDATE [Sessions]
SET [Is_Active] = @p0, [Disconnected] = @p1
WHERE 0 = 1
-- @p0: Input Boolean (Size = 0; Prec = 0; Scale = 0) [False]
-- @p1: Input DateTime (Size = 0; Prec = 0; Scale = 0) [9/4/2008 5:12:02 PM]
-- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.21022.8
The obvious problem is the **WHERE 0=1**, After the record was loaded, I've confirmed that all the properties in the "deviceSessionRecord" are correct to include the primary key. Also when catching the "ChangeConflictException" there is no additional information about why this failed. I've also confirmed that this exception get's thrown with exactly one record in the database (the record I'm attempting to update)
What's strange is that I have a very similar update statement in a different section of code and it generates the following SQL and does indeed update my SQL Server Compact Edition database.
UPDATE [Sessions]
SET [Is_Active] = @p4, [Disconnected] = @p5
WHERE ([Session_RecId] = @p0) AND ([App_RecId] = @p1) AND ([Is_Active] = 1) AND ([Established] = @p2) AND ([Disconnected] IS NULL) AND ([Member_Id] IS NULL) AND ([Company_Id] IS NULL) AND ([Site] IS NULL) AND (NOT ([Is_Device] = 1)) AND ([Machine_Name] = @p3)
-- @p0: Input Guid (Size = 0; Prec = 0; Scale = 0) [0fbbee53-cf4c-4643-9045-e0a284ad131b]
-- @p1: Input Guid (Size = 0; Prec = 0; Scale = 0) [7a174954-dd18-406e-833d-8da650207d3d]
-- @p2: Input DateTime (Size = 0; Prec = 0; Scale = 0) [9/4/2008 5:20:50 PM]
-- @p3: Input String (Size = 0; Prec = 0; Scale = 0) [CWMOBILEDEV]
-- @p4: Input Boolean (Size = 0; Prec = 0; Scale = 0) [False]
-- @p5: Input DateTime (Size = 0; Prec = 0; Scale = 0) [9/4/2008 5:20:52 PM]
-- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.21022.8
I have confirmed that the proper primary fields values have been identified in both the Database Schema and the DBML that generates the LINQ classes.
I guess this is almost a two part question:
1. Why is the exception being thrown?
2. After reviewing the second set of generated SQL, it seems like for detecting conflicts it would be nice to check all the fields, but I imagine this would be fairly inefficient. Is this the way this always works? Is there a setting to just check the primary key?
I've been fighting with this for the past two hours so any help would be appreciated.
Kevin... |
The documentation on [IDisposable][1] gives a pretty clear and detailed explaination of the behavior, as well as example code. The GC will NOT call the `Dispose()` method on the interface, but it will call the finalizer for your object.
[1]: http://msdn.microsoft.com/en-us/library/system.idisposable.aspx |
How do I suppress firefox password field completion? |
|html|firefox| |
I'm developing a website. I'm using a single-page web-app style, so all of the different parts of the site are AJAX'd into index.php. When a user logs in and tells Firefox to remember his username and password, all input boxes on the site get auto-filled with that username and password. This is a problem on the form to change a password. How can i prevent Firefox from automatically filling out these fields? I already tried giving them different names and ids. |
I'm developing a website. I'm using a single-page web-app style, so all of the different parts of the site are AJAX'd into index.php. When a user logs in and tells Firefox to remember his username and password, all input boxes on the site get auto-filled with that username and password. This is a problem on the form to change a password. How can i prevent Firefox from automatically filling out these fields? I already tried giving them different names and ids.
Edit: [Someone has already asked this][1]. Thanks Joel Coohorn.
[1]: http://stackoverflow.com/questions/32369/disable-browser-save-password-functionality |
How do I get list of recent files in GNU Emacs? |
|ide|emacs| |
When I use Emacs I want to be able to easily display and navigate through a list of files I worked on from not just the current session but from previous sessions. (BTW, running Emacs 22.2 on Windows) |
The CLR has a 'profiling API' that hooks into pretty much everything - it is what the commercial .NET memory profiling products use, I believe. Here is an MSDN link to the top level of the documentation: [.NET Framework General Reference: About the Profiling API][1]
See this MSDN magazine article for an introduction to the memory piece: [Inspect and Optimize Your Program's Memory Usage with the .NET Profiler API][2]
[1]: http://msdn.microsoft.com/en-us/library/bb384547.aspx
[2]: http://msdn.microsoft.com/en-us/magazine/cc188781.aspx |
I had to import `scala.collection.mutable.Set`. It seems the compiler thought the Set in `HashMap[Integer, Set[TreeNode]]` was `scala.collection.Set`. The Set in the MultiMap def is `scala.collection.`**`mutable`**`.Set`. |
The problem here is that you've accepted the burden of proof. You're unlikely to change someone's mind like that. Like it or not, people--even programmers-- are just too emotional to be easily swayed by logic. You need to put the burden of proof back on him- get him to convince you otherwise- and that will force him to do the research and discover the answer for himself.
A better argument to use stored procedures is security. If you use _only_ stored procedures, with no dynamic sql, you can disable SELECT, UPDATE, DELETE, ALTER, and CREATE permissions for the application database user. This will protect you against most 2nd order SQL Injection, whereas parameterized queries are only effective against first order injection. |
The problem here is that you've accepted the burden of proof. You're unlikely to change someone's mind like that. Like it or not, people--even programmers-- are just too emotional to be easily swayed by logic. You need to put the burden of proof back on him- get him to convince you otherwise- and that will force him to do the research and discover the answer for himself.
A better argument to use stored procedures is security. If you use _only_ stored procedures, with _no_ dynamic sql, you can disable SELECT, INSERT, UPDATE, DELETE, ALTER, and CREATE permissions for the application database user. This will protect you against most 2nd order SQL Injection, whereas parameterized queries are only effective against first order injection. |
(C) How do I determine the size of my array? |
|c|memory| |
i.e., the number of elements the array can hold? |
executive summary:
int a[17];
n = sizeof(a)/sizeof(a[0]);
To determine the size of your array in bytes, you can use the sizeof
operator:
int a[17];
int n = sizeof(a);
On my computer, ints are 4 bytes long, so n is 68.
To determine the number of elements in the array, we can divide
the total size of the array by the size of the array element.
You could do this with the type, like this
int a[17];
int n = sizeof(a) / sizeof(int);
and get the proper answer (68 / 4 = 17), but if the type of
a changed you would have a nasty bug if you forgot to change
the sizeof(int) as well.
So the preferred divisor is sizeof(a[0]), the size of the
zeroeth element of the array.
int a[17];
int n = sizeof(a) / sizeof(a[0]));
Another advantage is that you can now easily parameterize
the array name in a macro and get:
#define NELEMS(x) (sizeof(x) / sizeof(x[0]))
int a[17];
int n = NELEMS(a);
|
sizeof(array) / sizeof(array[0]) |
By taking a C string, the fstream class reduces dependency on the `std::string` class. Now, you may wonder then why isn't there a transparent conversion from a `std:string` to a C string, so a class that expects a C string could still take a `std::string` just like a class that expects a `std::string` can take a C string.
The reason is that this would cause a conversion cycle, which in turn may lead to problems. For example, suppose `std::string` would be convertible to a C string so that you could use `std::string`s with `fstream`s. Suppose also that C string are convertible to `std::string`s as is the state in the current standard. Now, consider the following:
void f(char* cstr, std::string str);
void f(std::string str, char* cstr);
void f(char* cstr1, char* cstr2);
void g()
{
char* cstr = "abc";
std::string str = "def";
f(cstr, str); // ERROR: ambiguous
}
Because you can convert either way between a `std::string` and a C string the call to `f()` could resolve to any of the three `f()` alternatives, and is thus ambiguous. The solution is to break the conversion cycle by making one conversion direction explicit, which is what the STL chose to do with `c_str()`. |
> Is there a way to determine at what
> point I would encounter a stack
> overflow?
Depends how deep you go, and how large the actual recursion is. I take it you understand what recursion does? |
@John (37479):
Very close, but then I lose everything from ClassX. Below is something a collegue gave me that does do the trick, but it's hideous. There has to be a better way.
import cgi
from math import sqrt
class ClassX(object):
def __repr__(self):
return "Best Guess"
class ClassY(object):
pass # ... with own __repr__
inst_x=ClassX()
inst_y=ClassY()
inst_z=[ i*i for i in range(25) ]
inst_b=True
avoid="__class__ __init__ __dict__ __weakref__"
class HTMLDecorator(object):
def __init__(self,master):
self.master = master
for attr in dir(self.master):
if ( not attr.startswith("__") or
attr not in avoid.split() and "attr" not in attr):
self.__setattr__(attr, self.master.__getattribute__(attr))
def html(self): # an "enhanced" version of __repr__
return cgi.escape(self.__repr__()).join(("<H1>","</H1>"))
def length(self):
return sqrt(sum(self.__iter__()))
print HTMLDecorator(inst_x).html()
print HTMLDecorator(inst_y).html()
wrapped_z = HTMLDecorator(inst_z)
print wrapped_z.length()
inst_z[0] += 70
#wrapped_z[0] += 71
wrapped_z.__setitem__(0,wrapped_z.__getitem__(0)+ 71)
print wrapped_z.html()
print HTMLDecorator(inst_b).html()
Output:
<pre><H1>Best Guess</H1>
<H1><__main__.ClassY object at 0x891df0c></H1>
70.0
<H1>[141, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576]</H1>
<H1>True</H1></pre> |
Is solving the halting problem easier than people think? |
|computability|language-agnostic|types|inference| |
Although the general case is undecidable, many people still do solve problems that are equivilent well enough for day to day use.
In cohen's phd thesis on computer viruses, he showed how virus scanning is equivilent to the halting problem, yet we have an entire industry based around this challenge.
I also have seen microsoft's terminator project - http://research.microsoft.com/Terminator/
Which leads me to ask - is the halting problem overrated - do we need to worry about the general case?
Will types become turning complete over time - dependant types do seem like a good development?
Or, to look the other way, will we begin to use non turing complete languages to gain the benefits of static analysis ? |
|language-agnostic|types|computability|inference| |
Although the general case is undecidable, many people still do solve problems that are equivilent well enough for day to day use.
In cohen's phd thesis on computer viruses, he showed how virus scanning is equivilent to the halting problem, yet we have an entire industry based around this challenge.
I also have seen microsoft's terminator project - http://research.microsoft.com/Terminator/
Which leads me to ask - is the halting problem overrated - do we need to worry about the general case?
Will types become turing complete over time - dependant types do seem like a good development?
Or, to look the other way, will we begin to use non turing complete languages to gain the benefits of static analysis ? |
I'm an idiot. I forgot the whole "a function can't own another function" thing, so I figured out another way to do it. Thanks! |
How do you give a C# Auto-Property a default value? |
|c#| |
How do you give a C# Auto-Property a default value? I either use the constructor, or revert to the old syntax.
<strong> Using the Constructor:</strong>
class Person
{
public Person()
{
Name = "Default Name";
}
public string Name { get; set; }
}
<strong>Using normal property syntax</strong> (with a default value)
public string name = "Default Name";
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
Is there a better way? |
Well, of course you could always implement the spec yourself. It's just that there's nothing built-in to support it. If you use Nathan Lee's solution, do it as an http handler (.ashx) rather than an aspx. You can just about copy/paste his code into a new handler file. |
We're in a very similar situation at the moment. Dozens of crystal reports in place and we're shifting to Reporting Services (mainly for its ease of deployment and more flexible UI for the end user) - our solution is to leave them be, but anything new is being created in RptgSvcs. Ideally we'd translate them, but the .rpt format is too opaque. |
I would forget about server side caching in this instance and rely on the simplicity of client side caching.
Your Javascript code could be client side cached just as easily as HTML, either by linking to an external javascript file and adding the necessary headers/expiries, or by embedding the script within the page itself and ensuring the page itself is cached.
Another possible method is by making an Ajax call on the page load to fetch the generated footer complete with correct link. This may take time on the first page load, but subsequent ajax requests would be cached on the client, thus seeing no penalty to future requests. |
@Dana & @John
Actually, `svn log -v -r <#> http://my.svn.server/repository-root` will work and show you all modified files within this repository. Or if you wanted this to work from within a working copy, you could use the output of `svn info | grep Repository Root` or something to find the actual repository root.
`--verbose` is the same as `-v`, and those options simply list all of the affected files. |
Many times the caller wants access just to iterate over the collection. Take a page out of Ruby's book and make the iteration a private aspect of your class.
#include <algorithm>
#include <boost/function.hpp>
class Blah
{
public:
void for_each_data(boost::function1<void, const mydata&> f) const
{
std::for_each(myPreciousData.begin(), myPreciousData.end(), f);
}
private:
typedef std::vector<mydata> mydata_collection;
mydata_collection myPreciousData;
};
With this approach you're not exposing anything about your internals, i.e. that you even _have_ a collection. |
No idea on the cause, but I just reconstructed my .dbml from scratch and it fixed itself.
Oh for a "refresh" feature... |
[@Ethan](http://stackoverflow.com/questions/42966/google-suggestish-text-box#45014)
I forgot about the fact that you would want to save that so it wasn't a per session only thing :P But yes, you are completely correct.
This is easily done, especially since it's just basic strings, just write out the contents of AutoCompleteCustomSource from the TextBox to a text file, on separate lines.
I had a few minutes, so I wrote up a complete code example...I would've before as I always try to show code, but didn't have time. Anyway, here's the whole thing (minus the designer code).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace AutoComplete
{
public partial class Main : Form
{
//so you don't have to address "txtMain.AutoCompleteCustomSource" every time
AutoCompleteStringCollection acsc;
public Main()
{
InitializeComponent();
//Set to use a Custom source
txtMain.AutoCompleteSource = AutoCompleteSource.CustomSource;
//Set to show drop down *and* append current suggestion to end
txtMain.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
//Init string collection.
acsc = new AutoCompleteStringCollection();
//Set txtMain's AutoComplete Source to acsc
txtMain.AutoCompleteCustomSource = acsc;
}
private void txtMain_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
//Only keep 10 AutoComplete strings
if (acsc.Count < 10)
{
//Add to collection
acsc.Add(txtMain.Text);
}
else
{
//remove oldest
acsc.RemoveAt(0);
//Add to collection
acsc.Add(txtMain.Text);
}
}
}
private void Main_FormClosed(object sender, FormClosedEventArgs e)
{
//open stream to AutoComplete save file
StreamWriter sw = new StreamWriter("AutoComplete.acs");
//Write AutoCompleteStringCollection to stream
foreach (string s in acsc)
sw.WriteLine(s);
//Flush to file
sw.Flush();
//Clean up
sw.Close();
sw.Dispose();
}
private void Main_Load(object sender, EventArgs e)
{
//open stream to AutoComplete save file
StreamReader sr = new StreamReader("AutoComplete.acs");
//initial read
string line = sr.ReadLine();
//loop until end
while (line != null)
{
//add to AutoCompleteStringCollection
acsc.Add(line);
//read again
line = sr.ReadLine();
}
//Clean up
sr.Close();
sr.Dispose();
}
}
}
This code will work exactly as is, you just need to create the GUI with a TextBox named txtMain and hook up the KeyDown, Closed and Load events to the TextBox and Main form.
Also note that, for this example and to make it simple, I just chose to detect the Enter key being pressed as my trigger to save the string to the collection. There is probably more/different events that would be better, depending on your needs.
Also, the model used for populating the collection is not very "smart." It simply deletes the oldest string when the collection gets to the limit of 10. This is likely not ideal, but works for the example. You would probably want some sort of rating system (especially if you really want it to be Google-ish)
A final note, the suggestions will actually show up in the order they are in the collection. If for some reason you want them to show up differently, just sort the list however you like.
Hope that helps! |
From an object-oriented perspective, sealing a class clearly documents the author's intent without the need for comments. When I seal a class I am trying to say that this class was designed to encapsulate some specific piece of knowledge or some specific service. It was not meant to be enhanced or subclassed further.
This goes well with the Template Method design pattern. I have an interface that says "I perform this service." I then have a class that implements that interface. But, what if performing that service relies on context that the base class doesn't know about (and shouldn't know about)? What happens is that the base class provides virtual methods, which are either protected or private, and these virtual methods are the hooks for subclasses to provide the piece of information or action that the base class does not know and cannot know. Meanwhile, the base class can contain code that is common for all the child classes. These subclasses would be sealed because they are meant to accomplish that one and only one concrete implementation of the service.
Can you make the argument that these subclasses should be further subclassed to enhance them? I would say no because if that subclass couldn't get the job done in the first place then it should never have derived from the base class. If you don't like it then you have the original interface, go write your own implementation class.
Sealing these subclasses also discourages deep levels of inheritence, which works well for GUI frameworks but works poorly for business logic layers. |
I can't speak to anything other than SQL Server, but the performance argument is **not** significantly valid there unless you're on 6.5 or earlier. SQL Server has been caching ad-hoc execution plans for roughly a decade now. |
It is the way s-boxes work. They can be m * n ==> m bit input , n bit output.
For example, in the [AES][1] S-box the number of bits in input is equal to the number of bits in output.
In [DES][2], m=6 and n=4.
The input is expanded from 32 to 48 bits in the first stages of DES. So it is be reduced to 32 bits again by applying one round of S-box substitution. Thus no information is lost here.
The Wikipedia article on itself can be confusing. It will make us think that information is lost. Actually, you should read the article in conjuncture with implementation details of some encryption algorithm using s-boxes.
[1]: http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
[2]: http://en.wikipedia.org/wiki/Data_Encryption_Standard |
It is the way s-boxes work. They can be m * n ==> m bit input , n bit output.
For example, in the [AES][1] S-box the number of bits in input is equal to the number of bits in output.
In [DES][2], m=6 and n=4.
The input is expanded from 32 to 48 bits in the first stages of DES. So it is be reduced to 32 bits again by applying one round of S-box substitution. Thus no information is lost here.
The Wikipedia article on itself can be a bit confusing. It will make people think that information is lost. You should read the article in conjuncture with implementation details of some encryption algorithm using s-boxes.
[1]: http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
[2]: http://en.wikipedia.org/wiki/Data_Encryption_Standard |
I'm looking for a Windows hosting provider that supports custom os images (like AMZN EC2) |
|windows2003server|hosting|virtual|cloud|amazon-ec2| |
I've come to love [Amazon's EC2 service][1] and I'm looking for something similar that supports the ability to save a running Windows server image and start new instances from it.
I contacted [GoGrid][2] (the feature is planned in future) and [Mosso][3] (no joy)
Anyone know of any hosting/cloud providers that can dothis?
[1]: http://en.wikipedia.org/wiki/Amazon_Elastic_Compute_Cloud
[2]: http://www.gogrid.com/
[3]: http://www.mosso.com/ |
|hosting|windows-server-2003|cloud|amazon-ec2|virtual| |
how to allow files starting with period and no extension in windows 2003 server? |
|mercurial|windows2003server| |
How can I create this file in a directory in windows 2003 SP2:
.hgignore
I get error: You must type a file name.
|
|windows-server-2003|mercurial| |
Personally, I try to always use *this* when referring to member variables. It helps clarify the code and make it more readable. Even if there is no ambiguity, someone reading through my code for the first time doesn't know that, but if they see *this* used consistently, they will know if they are looking at a member variable or not. |
Your SEO guru is slightly off the mark, but I understand the concern. This has nothing to do with whether or not the practice is proper, or whether or not a certain number of script tags is looked upon poorly by Google, but everything to do with page weight. Google stops caching after (I think) 150KB. The more inline scripts your page contains, the greater the chance important content will not be indexed because those scripts added too much weight. |
I've spent some time working on search engines (not Google), but have never really done much from an SEO perspective.
Anyway, here are some factors which Google could reasonably use to penalise the page which should be increased by including big blocks of javascript inline.
- Overall page size.
- Page download time (a mix of page size and download speed).
- How early in the page the search terms occurred (might ignore script tags, but that's a lot more processing).
Script tags with lots of inline javascript might be interpreted to be bad on their own. If users frequently loaded a lot of pages form the site, they'd find it much faster if the script was in a single shared file. |
I have tested many ways to remove the load of view state from the page and between all hacks and some software out there the only thing that it is truly scalable is the [StrangeLoops As10000 appliance][1]. Transparent, no need to change the underlying application.
[1]: http://www.strangeloopnetworks.com/products/AS1000/default.aspx |
Is there a .NET Control Similar to the Access 2007 Split Form? |
|.net|ms-access| |
Is there a .NET Control Similar to the Access 2007 Split Form?
Or has anyone built such a control?
I upgraded a small personal Name and Address DB to Access 2007 and noticed the Form had a property called “Default View” which can be set to “Split Form”. “Split Form” mode has a GridView and a Form together in one control. When a record is clicked in the GridView, it shows up in the form and it can be edited in either the GridView and/or the Form by setting some properties. Pretty slick.
|
Do you have access to any programmable hardware on the embedded device? Like counters and such? If so, you might be able to write a hardware based mod unit, instead of using the simulated %. (I did that once in VHDL. Not sure if I still have the code though.)
Mind you, you did say that division was 5-10 times faster. Have you considered doing a division, multiplication, and subtraction to simulated the mod?
In your specific case, though, you are checking for a mod of 6. 6 = 2*3. So you could MAYBE get some small gains if you first checked if the least significant bit was a 0. Something like:
if((!(x & 1)) && (x % 3))
{
print("Fizz\n");
}
If you do that, though, I'd recommend confirming that you get any gains, yay for profilers. And doing some commenting. I'd feel bad for the next guy who has to look at the code otherwise. |
Do you have access to any programmable hardware on the embedded device? Like counters and such? If so, you might be able to write a hardware based mod unit, instead of using the simulated %. (I did that once in VHDL. Not sure if I still have the code though.)
Mind you, you did say that division was 5-10 times faster. Have you considered doing a division, multiplication, and subtraction to simulated the mod? (Edit: Misunderstood the original post. I did think it was odd that division was faster than mod, they are the same operation.)
In your specific case, though, you are checking for a mod of 6. 6 = 2*3. So you could MAYBE get some small gains if you first checked if the least significant bit was a 0. Something like:
if((!(x & 1)) && (x % 3))
{
print("Fizz\n");
}
If you do that, though, I'd recommend confirming that you get any gains, yay for profilers. And doing some commenting. I'd feel bad for the next guy who has to look at the code otherwise. |