instruction
stringlengths
0
30k
Your simplest answer lies in the next version of css (3), which currently no browser supports. For now you are relegated to calculating heights in javascript and setting them on the left side. If the navigation is so important to be positioned in such a way, run it along the top. you could also do a visual trick by moving the borders to the container and the bigger inner, and make it appear to be the same size.
Your simplest answer lies in the next version of css (3), which currently no browser supports. For now you are relegated to calculating heights in javascript and setting them on the left side. If the navigation is so important to be positioned in such a way, run it along the top. you could also do a visual trick by moving the borders to the container and the bigger inner, and make it appear to be the same size. this makes it look the same, but it isn't. <div style="border-left:solid 1px black;border-bottom:solid 1px black;"> <div style="float:left; width: 150px; border-top: 1px solid;"> <ul> <li>nav1</li> <li>nav2</li> <li>nav3</li> <li>nav4</li> </ul> </div> <div style="float:left; width: 250px; border:solid 1px black;border-bottom:0;"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna Lorem ipsum dolor sit amet, consectetur adipisicing elit, ... </div> <div style="clear:both;" ></div> </div>
Anyone soloing using fogbugz?
|fogbugz|
Is there anyone working solo and using fogbugz out there? I'm interested in personal experience/overhead versus paper. I am involved in several projects and get pretty hammered with lots of details to keep track of... Any experience welcome. (Yes I know Mr. Joel is on the stackoverflow team... I still want good answers :)
I'm guessing Date.Parse() doesn't work?
Well then method 2 seems the best way: private function castMethod2(dateString:String):Date { if ( dateString == null ) { return null; } if ( dateString.indexOf("0000-00-00") != -1 ) { return null; } dateString = dateString.split("-").join("/"); return new Date(Date.parse( dateString )); }
I had no luck using the BinaryFormatter, I guess I have to have a complete struct that matches the content of the file exactly. I realised that in the end I wasn't interested in very much of the file content anyway so I went with the solution of reading part of stream into a bytebuffer and then converting it using Encoding.ASCII.GetString() for strings and BitConverter.ToInt32() for the integers. I will need to be able to parse more of the file later on but for this version I got away with just a couple of lines of code.
The best I've found is gedit unfortunately. Spend a few hours with it and you'll discover it's not so bad, with plugins and themes. You can use the command line to open documents in it.
Try [akismet][1] from wp guys [1]: http://akismet.com/
I use [SciTE][1] very small and simple text editor. [1]: http://www.scintilla.org/SciTE.html
Maybe he doesn't want to use **BinaryFormatter** because it's too slow. Anyway, I don't see any problem with your code. just out of my head, what if you try to do it manually? does it work? BinaryReader reader = new BinaryReader(stream); StructType o = new StructType(); o.FileDate = Encoding.ASCII.GetString(reader.ReadBytes(8)); o.FileTime = Encoding.ASCII.GetString(reader.ReadBytes(8)); ... ... ...
Maybe he doesn't want to use **BinaryFormatter** because it's too slow. Anyway, I don't see any problem with your code. just out of my head, what if you try to do it manually? does it work? BinaryReader reader = new BinaryReader(stream); StructType o = new StructType(); o.FileDate = Encoding.ASCII.GetString(reader.ReadBytes(8)); o.FileTime = Encoding.ASCII.GetString(reader.ReadBytes(8)); ... ... ... also try StructType o = new StructType(); byte[] buffer = new byte[Marshal.SizeOf(typeof(StructType))]; GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); Marshal.StructureToPtr(o, handle.AddrOfPinnedObject(), false); handle.Free(); then use **buffer[]** in your BinaryReader instead of reading data from FileStream to see whether you still get AccessViolation exception.
As far as I know, without programmatically generating the CSS file, there's no way to, say, define your favorite shade of blue (#E0EAF1) in one and only one spot. You could pretty easily write a computer program to generate the file. Execute a simple find-and-replace operation and then save as a .css file.
As far as I know, without programmatically generating the CSS file, there's no way to, say, define your favorite shade of blue (#E0EAF1) in one and only one spot. You could pretty easily write a computer program to generate the file. Execute a simple find-and-replace operation and then save as a .css file. Go from this source.css&hellip; h1,h2 { color: {YOURFAVORITECOLOR}; } div.something { border-color: {YOURFAVORITECOLOR}; } to this target.css&hellip; h1,h2 { color: #E0EAF1; } div.something { border-color: #E0EAF1; }
As far as I know, without programmatically generating the CSS file, there's no way to, say, define your favorite shade of blue (#E0EAF1) in one and only one spot. You could pretty easily write a computer program to generate the file. Execute a simple find-and-replace operation and then save as a .css file. Go from this source.css&hellip; h1,h2 { color: %%YOURFAVORITECOLOR%%; } div.something { border-color: %%YOURFAVORITECOLOR%%; } to this target.css&hellip; h1,h2 { color: #E0EAF1; } div.something { border-color: #E0EAF1; } with code like this&hellip; (VB.NET) Dim CssText As String = System.IO.File.ReadAllText("C:\source.css") CssText = CssText.Replace("%%YOURFAVORITECOLOR%%", "#E0EAF1") System.IO.File.WriteAllText("C:\target.css", CssText)
The most readable, IMO: SELECT * FROM TABLE WHERE Date > DATEADD(yy, -1, CONVERT(datetime, CONVERT(varchar, GETDATE(), 101))) Which: 1. Gets now's datetime *GETDATE() = #8/27/2008 10:23am#* 2. Converts to a string with format 101 *CONVERT(varchar, #8/27/2008 10:23am#, 101) = '8/27/2007'* 3. Converts to a datetime *CONVERT(datetime, '8/27/2007') = #8/27/2008 12:00AM#* 4. Subtracts 1 year *DATEADD(yy, -1, #8/27/2008 12:00AM#) = #8/27/2007 12:00AM#* There's variants with DATEDIFF and DATEADD to get you midnight of today, but they tend to be rather obtuse (though slightly better on performance - not that you'd notice compared to the reads required to fetch the data).
As many posters have already mentioned, you should use tables to display for tabular data. Tables were introduced in <a href="http://www.w3.org/TR/REC-html32.html#body">HTML 3.2</a> here is the relevant paragraph from the spec on their usage: > [tables] can be used to markup tabular material or for layout purposes...
Have you considered adding the DefaultValue as a static property of the ExtenderProvider, then you can access it without requiring an instance of the provider?
Here is a way to do it using a P/Invoke. public const int WM_NCLBUTTONDOWN = 0xA1; public const int HTCAPTION = 0x2; [DllImport("User32.dll")] public static extern bool ReleaseCapture(); [DllImport("User32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); void Form_Load(object sender, EventArgs e) { this.MouseDown += new MouseEventHandler(Form_MouseDown); } void Form_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { ReleaseCapture(); SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); } }
Remove duplicates from a List<T> in C#
|c#|generics|
Anyone have a quick method for de-duplicating a generic List<T> in C#?
I think the best approach to simulate it would be a **Fork** class with a method like *use*() that holds the fork (bool available = false) and a *release*() that releases it. A **Philosopher** class with *getFork*(**Fork**) and *releaseFork*(**Fork**) that operates the holding/releasing of the object Fork (seems to me a timer would be good in a method *useFork*() so you can really perceive the deadlock. And for Last a **DinningTable** (or any other name) class that Creates instances, and do the log. If you plan to use threads, here is where you should implement a thread for each **Philosopher** concurring for the Fork. As a suggestion, you could implement a **Plate** Class, holding a quantity of spaghetti that the **Philosopher**.*useFork*() method lower during the time frame. This way you can see which **Philosopher** finishes first. I will let the implementations for you, of course, since your objective is to learn C# ... and in my experience, you better learn doing something concrete like these classes ;) I invite you to share the code after it . It's a great Study Reference. Hope This helps you.
I think the best approach to simulate it would be a `Fork` class with a method like `use()` that holds the fork (`bool available = false`) and a `release()` that releases it. A `Philosopher` class with `getFork(Fork)` and `releaseFork(Fork)` that operates the holding/releasing of the object Fork (seems to me a timer would be good in a method `useFork()` so you can really perceive the deadlock. And for Last a `DinningTable` (or any other name) class that creates instances, and do the log. If you plan to use threads, here is where you should implement a thread for each `Philosopher` concurring for the `Fork`. As a suggestion, you could implement a `Plate` Class, holding a quantity of spaghetti that the `Philosopher.useFork()` method lower during the time frame. This way you can see which `Philosopher` finishes first. I will let the implementations for you, of course, since your objective is to learn C# ... in my experience, you better learn doing something concrete like these classes ;) Besides, you can find lots of implementations on Google if you want to cheat ... I invite you to share the code after it . It's a great Study Reference. Hope This helps you.
Tom is correct in describing exactly what the + operator does. It creates a temporary `StringBuilder`, appends the parts, and finishes with `toString()`. However, all of the answers so far are ignoring the effects of HotSpot runtime optimizations. Specifically, these temporary operations are recognized as a common pattern and are replaced with more efficient machine code at run-time. @marcio: You've created a micro-benchmark; with modern JVM's this is not a valid way to profile code. The reason run-time optimization matters is that many of these differences in code -- even including object-creation -- are completely different once HotSpot gets going. The only way to know for sure is profiling your code <i>in situ</i>. Finally, all of these methods are in fact incredibly fast. This might be a case of premature optimization. If you have code that concatenates strings a lot, the way to get maximum speed probably has nothing to do with which operators you choose and instead the algorithm you're using!
How do I create an HTML anchor in a FogBugz wiki page?
|wiki|fogbugz|
The StackOverflow transcripts are enormous, and sometimes I want to link to a little bit within it. How do I create an HTML anchor in a FogBugz wiki page?
When dealing with indexes, you have to determine what your table is going to be used for. If you are primarily inserting 1000 rows a second and not doing any querying, then a clustered index is a hit to performance. If you are doing 1000 queries a second, then not having an index will lead to very bad performance. The best thing to do when trying to tune queries/indexes is to use the Query Plan Analyzer and SQL Profiler in SQL Server. This will show you where you are running into costly table scans or other performance blockers. As for the GUID vs ID argument, you can find people online that swear by both. I have always been taught to use GUIDs unless I have a really good reason not to. Jeff has a good post that talks about the reasons for using GUIDs: <http://www.codinghorror.com/blog/archives/000817.html>. As with most anything development related, if you are looking to improve performance there is not one, single right answer. It really depends on what you are trying to accomplish and how you are implementing the solution. The only true answer is to test, test, and test again against performance metrics to ensure that you are meeting your goals.
When dealing with indexes, you have to determine what your table is going to be used for. If you are primarily inserting 1000 rows a second and not doing any querying, then a clustered index is a hit to performance. If you are doing 1000 queries a second, then not having an index will lead to very bad performance. The best thing to do when trying to tune queries/indexes is to use the Query Plan Analyzer and SQL Profiler in SQL Server. This will show you where you are running into costly table scans or other performance blockers. As for the GUID vs ID argument, you can find people online that swear by both. I have always been taught to use GUIDs unless I have a really good reason not to. Jeff has a good post that talks about the reasons for using GUIDs: <http://www.codinghorror.com/blog/archives/000817.html>. As with most anything development related, if you are looking to improve performance there is not one, single right answer. It really depends on what you are trying to accomplish and how you are implementing the solution. The only true answer is to test, test, and test again against performance metrics to ensure that you are meeting your goals. [Edit] After doing some more research on the GUID/ID debate I came across this post: > For example, there is an issue known as a "hotspot", where certain pages of data in a table are under relatively high currency contention. Basically, what happens is most of the traffic on a table (and hence page-level locks) occurs on a small area of the table, towards the end. New records will always go to this hotspot, because IDENTITY is a sequential number generator. These inserts are troublesome because they require Exlusive page lock on the page they are added to (the hotspot). This effectively serializes all inserts to a table thanks to the page locking mechanism. NewID() on the other hand does not suffer from hotspots. Values generated using the NewID() function are only sequential for short bursts of inserts (where the function is being called very quickly, such as during a multi-row insert), which causes the inserted rows to spread randomly throughout the table's data pages instead of all at the end - thus eliminating a hotspot from inserts. > Also, because the inserts are randomly distributed, the chance of page splits is greatly reduced. While a page split here and there isnt too bad, the effects do add up quickly. With IDENTITY, page Fill Factor is pretty useless as a tuning mechanism and might as well be set to 100% - rows will never be inserted in any page but the last one. With NewID(), you can actually make use of Fill Factor as a performance-enabling tool. You can set Fill Factor to a level that approximates estimated volume growth between index rebuilds, and then schedule the rebuilds during off-peak hours using dbcc reindex. This effectively delays the performance hits of page splits until off-peak times. >If you even *think* you might need to enable replication for the table in question - then you might as well make the PK a uniqueidentifier and flag the guid field as ROWGUIDCOL. Replication will require a uniquely valued guid field with this attribute, and it will add one if none exists. If a suitable field exists, then it will just use the one thats there. > Yet another huge benefit for using GUIDs for PKs is the fact that the value is indeed guaranteed unique - not just among all values generated by *this* server, but all values generated by *all* computers - whether it be your db server, web server, app server, or client machine. Pretty much every modern language has the capability of generating a valid guid now - in .NET you can use System.Guid.NewGuid. This is VERY handy when dealing with cached master-detail datasets in particular. You dont have to employ crazy temporary keying schemes just to relate your records together before they are committed. You just fetch a perfectly valid new Guid from the operating system for each new record's permanent key value at the time the record is created. > <http://forums.asp.net/t/264350.aspx>
When dealing with indexes, you have to determine what your table is going to be used for. If you are primarily inserting 1000 rows a second and not doing any querying, then a clustered index is a hit to performance. If you are doing 1000 queries a second, then not having an index will lead to very bad performance. The best thing to do when trying to tune queries/indexes is to use the Query Plan Analyzer and SQL Profiler in SQL Server. This will show you where you are running into costly table scans or other performance blockers. As for the GUID vs ID argument, you can find people online that swear by both. I have always been taught to use GUIDs unless I have a really good reason not to. Jeff has a good post that talks about the reasons for using GUIDs: <http://www.codinghorror.com/blog/archives/000817.html>. As with most anything development related, if you are looking to improve performance there is not one, single right answer. It really depends on what you are trying to accomplish and how you are implementing the solution. The only true answer is to test, test, and test again against performance metrics to ensure that you are meeting your goals. [Edit] @Matt, after doing some more research on the GUID/ID debate I came across this post. Like I mentioned before, there is not a true right or wrong answer. It depends on your specific implementation needs. But these are some pretty valid reasons to use GUIDs as the primary key: > For example, there is an issue known as a "hotspot", where certain pages of data in a table are under relatively high currency contention. Basically, what happens is most of the traffic on a table (and hence page-level locks) occurs on a small area of the table, towards the end. New records will always go to this hotspot, because IDENTITY is a sequential number generator. These inserts are troublesome because they require Exlusive page lock on the page they are added to (the hotspot). This effectively serializes all inserts to a table thanks to the page locking mechanism. NewID() on the other hand does not suffer from hotspots. Values generated using the NewID() function are only sequential for short bursts of inserts (where the function is being called very quickly, such as during a multi-row insert), which causes the inserted rows to spread randomly throughout the table's data pages instead of all at the end - thus eliminating a hotspot from inserts. > Also, because the inserts are randomly distributed, the chance of page splits is greatly reduced. While a page split here and there isnt too bad, the effects do add up quickly. With IDENTITY, page Fill Factor is pretty useless as a tuning mechanism and might as well be set to 100% - rows will never be inserted in any page but the last one. With NewID(), you can actually make use of Fill Factor as a performance-enabling tool. You can set Fill Factor to a level that approximates estimated volume growth between index rebuilds, and then schedule the rebuilds during off-peak hours using dbcc reindex. This effectively delays the performance hits of page splits until off-peak times. >If you even *think* you might need to enable replication for the table in question - then you might as well make the PK a uniqueidentifier and flag the guid field as ROWGUIDCOL. Replication will require a uniquely valued guid field with this attribute, and it will add one if none exists. If a suitable field exists, then it will just use the one thats there. > Yet another huge benefit for using GUIDs for PKs is the fact that the value is indeed guaranteed unique - not just among all values generated by *this* server, but all values generated by *all* computers - whether it be your db server, web server, app server, or client machine. Pretty much every modern language has the capability of generating a valid guid now - in .NET you can use System.Guid.NewGuid. This is VERY handy when dealing with cached master-detail datasets in particular. You dont have to employ crazy temporary keying schemes just to relate your records together before they are committed. You just fetch a perfectly valid new Guid from the operating system for each new record's permanent key value at the time the record is created. > <http://forums.asp.net/t/264350.aspx>
x86 Assembly on a mac...
|asm|macos|x86|xcode|
Does anyone know of any good tools (i'm looking for IDEs, primarily) to write assembly on the mac... XCode is a little cumbersome to me. Also, on the Intel Macs, can I use generic x86 asm? or is there a modified instruction set? Any information about post Intel Mac assembly helps.
|macos|xcode|x86|asm|
Does anyone know of any good tools (i'm looking for IDEs, primarily) to write assembly on the mac... XCode is a little cumbersome to me. Also, on the Intel Macs, can I use generic x86 asm? or is there a modified instruction set? Any information about post Intel Also: I know that on windows, asm can run in an emulated environment created by the OS to let the code think it's running on its own dedicated machine... does OSX provide the same thing?
Variation on @KG, using the milliseconds since EPOCH as the seed for rand?
I don't understand why you would use a custom control for that, when the builtin ASP.NET AJAX UpdatePanel does the same thing. It just adds more complexity, gives you less support, and makes it more difficult for others to work on your app.
According to [this support message](http://our.fogbugz.com/default.asp?fogbugz.4.25208), the feature is not yet currently implemented: > The FogBugz wiki does not currently support anchors within a document, unfortunately. It's definitely on the list of features we're considering for the next release, though.
The Haskell wikibook: <http://en.wikibooks.org/wiki/Haskell> which includes the text from the great tutorial Yet Another Haskell Tutorial.
The Haskell wikibook: <http://en.wikibooks.org/wiki/Haskell> which includes the text from the great tutorial Yet Another Haskell Tutorial. (The "Generic Haskell User Guide" paper is a fine paper, but I think it is a particularly bad recommendation for a beginning Haskell programmer, as it is more of an academic paper presenting extensions to Haskell and basically a different language "Generic Haskell" (i.e. Haskell with an old version of Generics) instead of standard Haskell 98. &lt;irony&gt;If you were looking for dense reading about Haskell, start with the <a href="http://haskell.org/onlinereport/">Haskell 98 report</a>.&lt;/irony&gt;)
Another route you could take is not to mess around with your own repository per se, for fear of messing things up, but you could use someone else's repository or set up your own elsewhere. Point being, I learned by using SourceForge, which has both CVS and SVN... but hearing good things about SVN and weighing the differences between the two, I of course went with SVN. Getting back to SourceForge, I applied for a test project, more or less to see how SourceForge worked... but once I was in I got to playing around with their SVN for my own project listed there; experimenting with it both remotely and locally. Once I got a broad grasp of its features through testing it there, I then went on to read the go-to book for SVN, the freely distributed book by the tool's authors(the book already mentioned). It's truly a great book and at that point I began to feel comfortable setting up my own repository on critical systems. From that point all you need is a Q&A site like this for specific issues you come across and of course keep the free SVN book referenced in a bookmark for easy access. Post your questions if you get stuck along the way and we'll be happy to help. Best of luck!
That topic is covered in depth here [Easily Change or Switch the Default Audio Sound Output in Vista or XP][1]. Note that sound management was changed in Vista significantly. On a side note, I believe [SnapStream][2] is/was working on an application to allo multi-channel sound cards to output to different rooms (sets of speakers) simultaneously. [1]: http://www.raymond.cc/blog/archives/2008/08/26/easily-change-or-switch-the-default-audio-sound-output-in-windows-vista-and-xp/ [2]: http://www.snapstream.com/
You should also checkout [syntaxhighlighter][1] from Google Code. [1]: http://code.google.com/p/syntaxhighlighter/
CreateProcessAsUser vs ShellExecute
|winapi|windows-nt|
I need to ShellExecute something as another user, currently I start a helper process with CreateProcessAsUser that calls ShellExecute, but that seems like too much of a hack (Wrong parent process etc.) Is there a better way to do this?
I need to ShellExecute something as another user, currently I start a helper process with CreateProcessAsUser that calls ShellExecute, but that seems like too much of a hack (Wrong parent process etc.) Is there a better way to do this? @PabloG: ImpersonateLoggedOnUser does not work: <pre> HANDLE hTok; VERIFY(LogonUser("otheruser",0,"password",LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,&hTok)); VERIFY(ImpersonateLoggedOnUser(hTok)); ShellExecute(0,0,"calc.exe",0,0,SW_SHOW); RevertToSelf(); CloseHandle(hTok); </pre> will just start calc as the logged in user, not "otheruser"
Tom is correct in describing exactly what the + operator does. It creates a temporary `StringBuilder`, appends the parts, and finishes with `toString()`. However, all of the answers so far are ignoring the effects of HotSpot runtime optimizations. Specifically, these temporary operations are recognized as a common pattern and are replaced with more efficient machine code at run-time. @marcio: You've created a [micro-benchmark][1]; with modern JVM's this is not a valid way to profile code. The reason run-time optimization matters is that many of these differences in code -- even including object-creation -- are completely different once HotSpot gets going. The only way to know for sure is profiling your code <i>in situ</i>. Finally, all of these methods are in fact incredibly fast. This might be a case of premature optimization. If you have code that concatenates strings a lot, the way to get maximum speed probably has nothing to do with which operators you choose and instead the algorithm you're using! [1]: http://www.ibm.com/developerworks/java/library/j-jtp02225.html
Sort it, then check two and two next to each others, as the duplicates will clump together. Something like this: list.Sort(); Int32 index = 0; while (index < list.Count - 1) { if (list[index] == list[index + 1]) list.RemoveAt(index); else index++; }
to andy47, I did not mean that you can use the empty string in a comparison, but oracle treats it like null if you use it in an insert. Re-read my entry, then try the following SQL: CREATE TABLE atable (acol VARCHAR(10)); INsERT INTO atable VALUES( '' ); SELECT * FROM atable WHERE acol IS NULL;
to andy47, I did not mean that you can use the empty string in a comparison, but oracle treats it like null if you use it in an insert. Re-read my entry, then try the following SQL: CREATE TABLE atable (acol VARCHAR(10)); INsERT INTO atable VALUES( '' ); SELECT * FROM atable WHERE acol IS NULL; And to avoid a "yes it is, no it isn't" situation, [here is an external link][1] [1]: http://www.adp-gmbh.ch/ora/misc/null.html
The Rails community has been very vocal in evangelising RoR, with the result that high expectations have been set and not always met (programmer productivity is good, but ensuring good performance once deployed isn't so easy). Grails has been designed as the scripted successor to Java, whereas the Ruby-Java integration used in JRuby on Rails, for example, has had to be retrofitted. I would suggest that you stick with Grails; it may not have the same glitz as RoR, but it's a pragmatic choice; you get improved productivity and the re-use of existing Java libraries.
Perhaps you should consider using a [HashSet][1]? [1]: http://msdn.microsoft.com/en-us/library/bb359438.aspx
I ran a similar test as @marcio but with the following loop instead: String c = a; for (long i = 0; i < 100000L; i++) { c = c.concat(b); // make sure javac cannot skip the loop // using c += b for the alternative } Just for good measure, I threw in `StringBuilder.append()` as well. Each test was run 10 times, with 100k reps for each run. Here are the results: - `StringBuilder` wins hands down. The clock time result was 0 for most the runs, and the longest took 16ms. - `a += b` takes about 40000ms (40s) for each run. - `concat` only requires 10000ms (10s) per run. I haven't decompiled the class to see the internals or run it through profiler yet, but I suspect `a += b` spends much of the time creating new objects of `StringBuilder` and then converting them back to `String`.
I don't see any problem with your code. just out of my head, what if you try to do it manually? does it work? BinaryReader reader = new BinaryReader(stream); StructType o = new StructType(); o.FileDate = Encoding.ASCII.GetString(reader.ReadBytes(8)); o.FileTime = Encoding.ASCII.GetString(reader.ReadBytes(8)); ... ... ... also try StructType o = new StructType(); byte[] buffer = new byte[Marshal.SizeOf(typeof(StructType))]; GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); Marshal.StructureToPtr(o, handle.AddrOfPinnedObject(), false); handle.Free(); then use **buffer[]** in your BinaryReader instead of reading data from FileStream to see whether you still get AccessViolation exception. > I had no luck using the > BinaryFormatter, I guess I have to > have a complete struct that matches > the content of the file exactly. That makes sense, BinaryFormatter has its own data format, completely incompatible with yours.
I think asking the user simple questions like: "How many legs does a dog have?" Would be much more effective that any CAPTCHA systems out there at the moment. Not only is it very difficult for the computer to answer that question, but it is **very easy for a human to answer**!
+1 for pico/nano -- lightweight, gets the job done, good help
If you used Server.MapPath, then you should already have the relative web path. According to the [MSDN documentation][1], this method takes one variable, *path*: > Specifies the relative or virtual path > to map to a physical directory. If > Path starts with either a forward (/) > or backward slash (\), the MapPath > method returns a path as if Path were > a full, virtual path. If Path doesn't > start with a slash, the MapPath method > returns a path relative to the > directory of the .asp file being > processed. So if you were able to call the method, you should already have the relative web path immediately accessible. [1]: http://msdn.microsoft.com/en-us/library/ms524632.aspx
If you used Server.MapPath, then you should already have the relative web path. According to the [MSDN documentation][1], this method takes one variable, *path*, which is the virtual path of the Web server. So if you were able to call the method, you should already have the relative web path immediately accessible. [1]: http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx
Kate, the KDE Advanced Text Editor is quite good. It has syntax highlighting, block selection mode, terminal/console, sessions, window splitting both horizontal and vertical etc.
Altova's [XML Spy](http://www.altova.com/products/xmlspy/xml_editor.html) is a great editor, but not necesarily the cheapest option out there.
I found that if you append the last modified timestamp of the file onto the end of the URL the browser will request the files when it is modified. For example in PHP: function urlmtime($url) { $parsed_url = parse_url($url); $path = $parsed_url['path']; if ($path[0] == "/") { $filename = $_SERVER['DOCUMENT_ROOT'] . "/" . $path; } else { $filename = $path; } if (!file_exists($filename)) { // If not a file then use the current time $lastModified = date('YmdHis'); } else { $lastModified = date('YmdHis', filemtime($filename)); } if (strpos($url, '?') === false) { $url .= '?ts=' . $lastModified; } else { $url .= '&ts=' . $lastModified; } return $url; } function include_css($css_url, $media='all') { // According to Yahoo, using link allows for progressive // rendering in IE where as @import url($css_url) does not echo '<link rel="stylesheet" type="text/css" media="' . $media . '" href="' . urlmtime($css_url) . '">'."\n"; } function include_javascript($javascript_url) { echo '<script type="text/javascript" src="' . urlmtime($javascript_url) . '"></script>'."\n"; }
If you go into the submit options, there is an option to perform custom action using rules. If you have all of the data connections set up, you can configure rules to select which connection to submit to.
Format numbers to strings in Python
|python|
I need to find out how to format numbers as strings. My code is here: return str(hours)+":"+str(minutes)+":"+str(seconds)+" "+ampm Hours and minutes are integers, and seconds is a float. the str() function will convert all of these numbers to the tenths (0.1) place. So instead of my string outputting "5:30:59.07 pm", it would display something like "5.0:30.0:59.1 pm". Bottom line, what library / function do I need to do this for me?
I'd say that any of the current iMac models are more that good enough for development with their dual core, 6MB cache, 1066MHz FSB cpus. You might consider going with more than 1GB of ram, but compare aftermarket prices at places like <a href="http://www.newegg.com/">NewEgg</a> to what Apple wants (for example, I upgraded my MacBook Pro to 4GB for hundreds less than getting installed from Apple). Which model you picked would be more about HD and LCD size and how much you have to spend.
Formatting in Python is done via the [string formatting (`%`) operator](http://docs.python.org/lib/typesseq-strings.html): "%02d:%02d:%02d" % (hours, minutes, seconds) /Edit: There's also [strftime](http://docs.python.org/lib/module-time.html#l2h-2826).
A great book if you're just beginning is Matthew MacDonald's [Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional][1]. Once you're done with that a great reference (also by MacDonald) is [Pro ASP.NET 3.5 in C# 2008][2]. One of my favorite sources of information online is [4GuysFromRolla][3]. [1]: http://www.amazon.com/Beginning-ASP-NET-3-5-2008-Professional/dp/1590598911/ref=pd_bbs_6?ie=UTF8&s=books&qid=1219417630&sr=8-6 [2]: http://www.amazon.com/Pro-ASP-NET-2008-Second-Windows-Net/dp/1590598938/ref=pd_bbs_sr_4?ie=UTF8&s=books&qid=1219417630&sr=8-4 [3]: https://web.archive.org/web/20211027112438/https://aspnet.4guysfromrolla.com/default.aspx
You can use C style string formatting: "%d:%d:d" % (hours, minutes, seconds) See here, especially: http://diveintopython.org/native_data_types/formatting_strings.html
Mercurial Stuck
|mercurial|
Got a bluescreen in windows while cloning a mercurial repository. After reboot, I now get this message for almost all hg commands: c:\src\>hg commit waiting for lock on repository c:\src\McVrsServer held by '\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' interrupted! Google is no help. Any tips?
Mercurial "Stuck waiting for lock"
Mercurial stuck "waiting for lock"
While you can differenciate the code execution looking the exception don't matter if it's done by the "catch exceptionType hierarchy mode" or by "if(...) else...exception code mode" but if you are developing software wich is going to be used by other people, like a library i think it's usefull create your own exception types to notice the other people that your sofware can throw other exceptions than the normal ones, and they better catch and resolve them. When i use a library and their methods simply launch an 'Exception' i allways wonder: What can cause this exception?, how must my program react?, if there is a javadoc maybe the cause will be explained, but mustly of times there is not a javadoc or the exception is not explained. Too much overhead witch can be avoided with a WellChossenExceptionTypeName
Provided this question is properly tagged, you can select LAMP server option during installation of Ubuntu. This will install and configure all required components automatically. A detailed instruction on how to do this can be found, for example, there: [http://www.ubuntugeek.com/ubuntu-804-hardy-heron-lamp-server-setup.html][1] [1]: http://www.ubuntugeek.com/ubuntu-804-hardy-heron-lamp-server-setup.html
"Send to --> Compressed (zipped) Folder" creates a zip file. What it puts in there is based on your settings. It does not include hidden files with the default settings. If you have your explorer view settings set as Kibbee mentioned to "Show hidden files and folders", then "Send to --> Compressed (zipped) Folder" will put the hidden files into the zip file. Files starting with "." have no special to windows except that Windows Explorer won't let you create one. It is a valid file name though.
"Send to --> Compressed (zipped) Folder" creates a zip file. What it puts in there is based on your settings. It does not include hidden files with the default settings. If you have your explorer view settings set as Kibbee mentioned to "Show hidden files and folders", then "Send to --> Compressed (zipped) Folder" will put the hidden files into the zip file. There is what I would call a bug in XP where hidden folders aren't include when recursing a folder tree. You can get them if they are in the folder that you are in. Recursing works in Vista. Files starting with "." have no special to windows except that Windows Explorer won't let you create one. It is a valid file name though. I would recommend using something like [7-Zip][1] if your folders contain hidden/system files/folders. [1]: http://www.7-zip.org/
>I dont´t know ASP.NET MVC, but I am very familiar with MVC pattern. I don´t see another way to build professional applications without MVC. And it has to be MVC model 2, like Spring or Struts. By the way, how you people were building web applications without MVC? When you have a situation that some kind of validation is necessary on every request, as validating if user is authenticated, what is your solution? Some kind of include(validate.aspx) in every page? Have you never heard of N-Tier development?
`menuItem.Icon = new BitmapImage(new Uri("images/sample.png", UriKind.Relative));`
NullReferenceException on User Control handle
|asp.net|user-controls|
I have an Asp.NET application (VS2008, Framework 2.0). When I try to set a property on one of the user controls like myUserControl.SomeProperty = someValue; I get a NullReferenceException. When I debug, I found out that myUserControl is null. How is it possible that a user control handle is null? How do I fix this or how do I find what causes this?
<MenuItem> <MenuItem.Icon> <Image.Source> <BitmapImage UriSource="/your_assembly;component/yourpath/Image.png" /> </Image.Source> </MenuItem.Icon> </MenuItem> Just make sure your image in also included in the project file and marked as resource, and you are good to go :)
How-to: Ranking Search Results
|php|mysql|search|
I have a webapp development problem that I've developed one solution for, but am trying to find other ideas that might get around some performance issues I'm seeing. problem statement: - a user enters several keywords/tokens - the application searches for matches to the tokens - need one result for each token - ie, if an entry has 3 tokens, i need the entry id 3 times - rank the results - assign X points for token match - sort the entry ids based on points - if point values are the same, use date to sort results What I want to be able to do, but have not figured out, is to send 1 query that returns something akin to the results of an in(), but returns a duplicate entry id for each token matches for each entry id checked. Is there a better way to do this than what I'm doing, of using multiple, individual queries running one query per token? If so, what's the easiest way to implement those?
Read Luke Kanies' discussion of exactly this question in [this blog post][1]. He references [a post from Jay Fields][2] which even suggests that using [a equivalent to ruby's/mocha's] stub_everything is preferrable to make the tests more robust. To quote Fields' final words: "Mocha makes it as easy to define a mock as it is to define a stub, but that doesn't mean you should always prefer mocks. In fact, I generally prefer stubs and use mocks when necessary." [1]: http://www.madstop.com/ruby/jay_and_i_converge_on_testing.html [2]: http://blog.jayfields.com/2008/05/using-stubs-to-capture-test-essence.html
Is there a way to attach a debugger to a multi-threaded python process?
|python|debugging|
I'm trying to debug a deadlock in a multi-threaded python app after it has locked up. Is there a way to attach a debugger to inspect the state of the process?
I'm trying to debug a deadlock in a multi-threaded python app after it has locked up. Is there a way to attach a debugger to inspect the state of the process? Edit: I'm attempting this on Linux, but it would be great if there were a cross-platform solution. It's Python after all :)
You have probably touched on a much larger issue of designing for high scalability and performance in general. Essentially, for your database design I would follow good practices such as adding foreign keys and indexes to data you expect to be used frequently, normalise your data by splitting it into smaller tables and identify which data is to be read frequently and which is to be written frequently and optimise. Much more important than your database design for high performance web applications, is your effective use of caching both at the client level through HTML page caching and at the server level through cached data or serving up static files in place of dynamic files. The great thing about caching is that it can be added as it is needed, so that when your application does take off then you evolve accordingly.
You have probably touched on a much larger issue of designing for high scalability and performance in general. Essentially, for your database design I would follow good practices such as adding foreign keys and indexes to data you expect to be used frequently, normalise your data by splitting it into smaller tables and identify which data is to be read frequently and which is to be written frequently and optimise. Much more important than your database design for high performance web applications, is your effective use of caching both at the client level through HTML page caching and at the server level through cached data or serving up static files in place of dynamic files. The great thing about caching is that it can be added as it is needed, so that when your application does take off then you evolve accordingly. As far as your historical data is concerned, this is a great thing to cache as you do not expect it to change frequently. If you wish to produce regular and fairly intensive reports from your data, then it is good practise to put this data into another database so as not to bring your web application to a halt whilst they run. Of course this kind of optimisation really isn't necessary unless you think your application will warrant it.
I need to ShellExecute something as another user, currently I start a helper process with CreateProcessAsUser that calls ShellExecute, but that seems like too much of a hack (Wrong parent process etc.) Is there a better way to do this? @PabloG: ImpersonateLoggedOnUser does not work: <pre> HANDLE hTok; VERIFY(LogonUser("otheruser",0,"password",LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,&hTok)); VERIFY(ImpersonateLoggedOnUser(hTok)); ShellExecute(0,0,"calc.exe",0,0,SW_SHOW); RevertToSelf(); CloseHandle(hTok); </pre> will just start calc as the logged in user, not "otheruser" @1800 INFORMATION: CreateProcess/CreateProcessAsUser is not the same as ShellExecute, with UAC on Vista, CreateProcess is useless when you don't have control over what program the user is executing (CreateProcess will return with a error if you give it a exe file with a manifest marked as requireAdmin)
I need to ShellExecute something as another user, currently I start a helper process with CreateProcessAsUser that calls ShellExecute, but that seems like too much of a hack (Wrong parent process etc.) Is there a better way to do this? @PabloG: ImpersonateLoggedOnUser does not work: <pre> HANDLE hTok; VERIFY(LogonUser("otheruser",0,"password",LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,&hTok)); VERIFY(ImpersonateLoggedOnUser(hTok)); ShellExecute(0,0,"calc.exe",0,0,SW_SHOW); RevertToSelf(); CloseHandle(hTok); </pre> will just start calc as the logged in user, not "otheruser" @1800 INFORMATION: CreateProcess/CreateProcessAsUser is not the same as ShellExecute, with UAC on Vista, CreateProcess is useless when you don't have control over what program the user is executing (CreateProcess will return with a error if you give it a exe file with a manifest marked as requireAdmin) @Brian R. Bondy: I already know this info (And don't get me wrong, its good stuff), but it is off topic (IMHO) I am asking for a "ShellExecuteAsUser", not about starting processes as another user, I already know how to do that.
I use [pygame][1] myself and it is very good. It has good documentation and tutorials, and is quite well designed. I've also heard wonderful reviews of [pyglet][2]. [1]: http://www.pygame.org/news.html [2]: http://www.pyglet.org/