instruction
stringlengths
0
30k
|c#|.net|winforms|
I'm developing a WinForms application (.Net 3.5, no WPF) where I want to be able to display foreign key lookups in a databound datagridview. An example of the sort of relationship is that I have a table of orderlines. Orderslines have a foreign key relationship to Products and Products in turn have a foreign key relationship to ProductTypes. I'd like to have a databound datagridview where each row represents an orderline, displaying the line's product and producttype. Users can add or edit orderlines direct to the grid and choose the product for the orderline from a comboBoxColumn - this should then update the producttype column, showing the producttype for the selected product, in the same row. The closest to a good fit I've found so far is to introduce a domain object representing an orderline then bind the datagridview to a collection of these orderlines. I then add properties to the orderline object that expose the product and the producttype, and raise relevant notifypropertychanged events to keep everything up to date. In my orderline repository I can then wire up the mappings between this orderline object and the three tables in my database. This works for the databinding side of things, but having to hand code all that OR-mapping in the repository seem bad. I thought nHibernate would be able to help with this wiring up but am struggling with the mappings through all the foreign keys - they seem to work ok (the foreignkey lookup for an orderline's product creates the correct product object based on the foreign key) until I try to do the databinding, I can't get the databound id columns to update my product or producttype objects. Is my general approach even in the right ballpark? If it is, what is a good solution to the mapping problem? Or, is there a better solution to databinding rows including foreign key lookups that I haven't even considered?
How do you get the filename of a tempfile to use in Linux?
|tempfile|linux|c|
Let's say I'm creating a program in C that needs to use a tempfile. Creating an ad hoc tempfile in /tmp is probably not a good idea. Is there a function or OS call to supply me with a tempfile name so that I can begin to write and read from it?
|c|linux|
You can use the [`mkstemp(3)`][1] function for this purpose. Another alternative is the [`tmpfile(3)`][2] function. Which one of them you choose depends on whether you want the file to be opened as a C library file stream (which `tmpfile` does), or a direct file descriptor (`mkstemp`). The `tmpfile` function also deletes the file automatically when you program finishes. The advantage of using these functions is that they avoid race conditions between determining the unique filename and creating the file -- so that two programs won't try to create the same file at the same time, for example. See the man pages for both functions for more details. [1]: http://www.linuxmanpages.com/man3/mkstemp.3.php [2]: http://www.linuxmanpages.com/man3/tmpfile.3.php
Absolutely: man mkstemp. The man page has example usage.
@dragonmantank In Xinc's case, I hope you used PEAR to install it. pear list-files xinc/Xinc This should do it, and show you where your Xinc install put its files. So even though Xinc is "just" one big PHP script, it's still spread out into rc scripts and all those other things which are necessary to make an application run. I'm sure you don't need to add all paths listed there, but probably some in order to make it run. Aside from Xinc itself, I think it also needs phpUnit and a bunch of other PEAR libs to run, so what I'd propose is this: pear config-get php_dir And then you need to add that path (like Henrik suggested) to the chroot environment.
If your willing to use JQuery, I would use [Set Hover Class for Anything][1] technique. [1]: http://www.learningjquery.com/2007/02/quick-tip-set-hover-class-for-anything
designing Panels without a parent Form in VS?
|visual-studio|
Does anyone know of any tools/plugins that allow you to design a Panel independently of a Form (Windows, not Web Form) within Visual Studio? I've been using the designer and manually extracting the bits I want from the source, but surely there is a nicer way.
You could just write the code by hand!
> I've found a few bits of software that suggest they might do this - but they either > refuse to compile, or don't seem to work properly. Has anyone got any suggestions? Write one. You're best off picking a nice, simple instruction set (Z80 should be perfect). I remember doing this as a first-year undergraduate exercise - I think we wrote the simulator in C++ and simulated 6800 assembly, but really any language/instruction set will do. The idea of "learning assembly language" these days is to get the idea of how computers work at the lowest level, only a select few (compiler writers, etc.) have any real reason to actually be writing assembly code these days. Modern processors are stuffed full of features designed to be used by compilers to help optimise code for speed/concurrent execution/power consumption/etc., and trying to write assembly by hand for a modern processor would be a nightmare. Don't fret about getting your application production-ready unless you want to - in all likelihood the bits of software you've found so far were written by people exactly like you who wanted to figure out how assembly works and wrote their own simulator, then realised how much work would be involved in getting it "production ready" so the general public could use it.
Either 1/0 or Y/N with a check constraint on it. ether way is fine. I personally prefer 1/0 as I do alot of work in perl, and it makes it really easy to do perl Boolean operations on database fields. If you want a really in depth discussion of this question with one of Oracles head honchos, check out what Tom Kyte has to say about this [Here][1] [1]: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6263249199595
Another alternative that will fix many more issues in one go is to use [IE7.js][1]. [1]: http://code.google.com/p/ie7-js/
You could do all the design work inside of a UserControl. If you go that route, instead of just copying the bits out of the user control, simply use the user control itself.
I'd strongly recommend saving each request to some file. -- This way, you can always go back to the actual contents of it later. You can thank me later, when you find that hostile-endian, koi-8 encoded, [...], whatever it was that stumped your parser...
How to enable multisampling for a wxWidgets OpenGL application?
|opengl|wxwidgets|multisampling|
**[Multisampling][1]** is a way of applying **full screen anti-aliasing** (FSAA) in 3D applications. I need to use multisampling in my OpenGL application, which is currently embedded in a **wxWidgets** GUI. Is there a way to do this? Please respond only if you know the detailed steps to achieve this. I'm aware that of enabling multisampling using **[WGL][2]** (Win32 extensions to OpenGL). However, since my OpenGL application isn't written in MFC (and I want the code to be multi-platform portable), that's not an option for me. [1]: http://en.wikipedia.org/wiki/Multisample_anti-aliasing [2]: http://is.gd/1Opr
**[Multisampling][1]** is a way of applying **full screen anti-aliasing** (FSAA) in 3D applications. I need to use multisampling in my OpenGL application, which is currently embedded in a **wxWidgets** GUI. Is there a way to do this? Please respond only if you know the detailed steps to achieve this. I'm aware of enabling multisampling using **[WGL][2]** (Win32 extensions to OpenGL). However, since my OpenGL application isn't written in MFC (and I want the code to be multi-platform portable), that's not an option for me. [1]: http://en.wikipedia.org/wiki/Multisample_anti-aliasing [2]: http://is.gd/1Opr
How to enable multisampling for a wxWidgets OpenGL program?
**[Multisampling][1]** is a way of applying **full screen anti-aliasing** (FSAA) in 3D applications. I need to use multisampling in my OpenGL program, which is currently embedded in a **wxWidgets** GUI. Is there a way to do this? Please respond only if you know the detailed steps to achieve this. I'm aware of enabling multisampling using **[WGL][2]** (Win32 extensions to OpenGL). However, since my OpenGL program isn't written in MFC (and I want the code to be multi-platform portable), that's not an option for me. [1]: http://en.wikipedia.org/wiki/Multisample_anti-aliasing [2]: http://is.gd/1Opr
There is a good article from 4 guys about [Encrypting Configuration Information in ASP.NET 2.0 Applications][1] Hope this helps [1]: https://web.archive.org/web/20211029043331/https://aspnet.4guysfromrolla.com/articles/021506-1.aspx
mktime(...) mktime(tuple) -> floating point number Convert a time tuple in local time to seconds since the Epoch. local time... fancy that. The time tuple: The other representation is a tuple of 9 integers giving local time. The tuple items are: year (four digits, e.g. 1998) month (1-12) day (1-31) hours (0-23) minutes (0-59) seconds (0-59) weekday (0-6, Monday is 0) Julian day (day in the year, 1-366) DST (Daylight Savings Time) flag (-1, 0 or 1) If the DST flag is 0, the time is given in the regular time zone; if it is 1, the time is given in the DST time zone; if it is -1, mktime() should guess based on the date and time. Incidentally, we seem to be 6 hours apart: >>> time.mktime((2009, 1, 31, 0, 0, 0, 5, 31, -1)) 1233356400.0 >>> (1233378000.0 - 1233356400)/(60*60) 6.0
Theoretically, no, they are not unique. It's possible to generate an identical guid over and over. However, the chances of it happening are so low that you can assume they are unique. I've read before that the chances are so low that you really should stress about something else--like your server spontaneously combusting or other bugs in your code. That is, assume it's unique and don't build in any code to "catch" duplicates--spend your time on something more likely to happen (i.e. *anything* else). I [made an attempt][1] to describe the usefulness of GUIDs to my blog audience (non-technical family memebers). From there (via Wikipedia), the odds of generating a duplicate GUID: - 1 in 2^128 - 1 in 340 undecillion (don’t worry, undecillion is not on the quiz) - 1 in 3.4 × 10^38 - 1 in 340,000,000,000,000,000,000,000,000,000,000,000,000 [1]: http://www.wassupy.com/20080105/technology/pick-a-number-any-number
I haven't tried it myself, but [Huagati DBML/EDMX Tools][1] is recommended by other people. > Huagati DBML/EDMX Tools is an add-in > for Visual Studio that adds > functionality to the Linq2SQL/DBML > diagram designer in Visual Studio > 2008, and to the ADO.NET Entity > Framework designer in Visual Studio > 2008 SP1. The add-in adds new menu > options for updating Linq2SQL designer > diagrams with database changes, for > renaming Linq-to-SQL (DBML) and EF > (EDMX) classes and properties to use > .net naming conventions, and for > adding documentation/descriptions to > Linq-to-SQL generated classes from the > database properties. ![Screenshot of DBML Tools][2] [1]: http://www.huagati.com/dbmltools/ [2]: http://www.huagati.com/dbmltools/screenshots/DBMLToolMenuOptions_3166.png
@e-bartek, I think that window[functionName] won't work if you in some closure, and the function name is local to that closure. For example: function foo() { var bar = function () { alert('hello world'); }; var s = 'bar'; window[s](); // this won't work } In this case, s is 'bar', but the function 'bar' only exists inside the scope of the function 'foo'. It is not defined in the window scope. Of course, this doesn't really answer the original question, I just wanted to chime in on this response. I don't believe there is a way to do what the original question asked.
Here are a few resources that might help you in your quest to create browser helper objects (BHO). [http://petesearch.com/wiki/][1] [http://www.hackszine.com/blog/archive/2007/06/howto_port_firefox_extensions.html][2] [http://msdn.microsoft.com/en-us/library/ms182554(VS.80).aspx][3] http://www.codeplex.com/TeamTestPlugins Edit: Can't get the msdn link to work with markdown, probably because it contains parens. [1]: http://petesearch.com/wiki/ [2]: http://www.hackszine.com/blog/archive/2007/06/howto_port_firefox_extensions.html [3]: http://msdn.microsoft.com/en-us/library/ms182554(VS.80).aspx
We have also used UTL_HTTP in a manner similar to what you have described. I don't have any direct experience with UTL_DBWS, so I hope you can follow up with any information/experience you can gather. @kogus, no it's a quite good design for many applications. PL/SQL is a full-fledged programming language that has been used for many big applications.
One thing that comes to mind is that you could have each thread writing to its own log file and then do a daily batch run to combine them. If you are logging to database you probably need to do some tuning and optimization, especially if the DB will be across the network. At the least you will need to be reusing the DB connections. Furthermore, do you have any specific needs to have the log in database? If all you need is a "grep <record-id>" then I don't think you gain much by logging into database.
Not sure about anything in a C lib, but you can do this at the shell with [mktemp][1]. [1]: http://linux.die.net/man/1/mktemp
> I'm starting to think it can't be done that way since there doesn't seem to be a way to maintain the offset counter between calls. Is that right, or is there something I'm missing. You aren't missing anything; SQL Server does not support global variables, and it doesn't support data modification within UDFs. And even if you wanted to do something as kludgy as using CONTEXT_INFO (see <http://weblogs.sqlteam.com/mladenp/archive/2007/04/23/60185.aspx>), you can't set that from within a UDF anyway. Is there a way you can get around the "hardcoding" of the offset by making that a variable and looping over the iteration of it, doing the inserts within that loop?
welcome to StackOverflow :) Normally what you would do is base the information in the drop down on two values [ValueMember and DisplayMember](http://windowsclient.net/blogs/faqs/archive/2006/07/12/what-are-the-displaymember-and-valuemember.aspx). The ValueMember is the source of the actual controls value (this will be the key value in the order line), the display member is the value that is displayed to the user instead of the value (this will be the FK value). Is there no particular reason you cannot just return all the data required and set these properties?
How to catch SQLServer timeout exceptions
|c#|.net|sql-server|error-handling|
I need to specifically catch SQL server timeout exceptions so that they can be handled differently. I know I could catch the SqlException and then check if the message string Contains "Timeout" but was wondering if there is a better way to do it? try { //some code } catch (SqlException ex) { if (ex.Message.Contains("Timeout")) { //handle timeout } else { throw; } }
Free Wavetable Synthesizer?
|audio|microcontroller|arm|synth|
I need to implement a [wavetable synthesizer][1] in an ARM Cortex-M3 core. I'm looking for any code or tools to help me get started. I'm aware of [this AVR implementation][2]. I actually converted it to a PIC a while back. Now I am looking for something similar, but a little better sounding. ANSI C code would be great. Any code snippets (C or C++), samples, tools, or just general information would be greatly appreciated. Thanks. [1]: http://en.wikipedia.org/wiki/Wavetable [2]: http://elm-chan.org/works/mxb/report.html
It should just fine. However some spam filters will do a reverse lookup on the originating IP address and see if it's assigned to the domain name the email claims to be from, and some may check to see if the IP is an actual MX for the domain. So the downside is that some recipients may never get the email, and you may not know about it for a long time. I'd suggest routing your mail through an established MX rather than having a webserver do it directly (there are some security implications there too).
In C, C++ and Java, the statement: <code><pre> if (condition1 | condition2) { ... } </code></pre> will evaluate both conditions every time and only be true if the entire expression is true. The statement: <pre><code> if (condition1 || condition2) { ... } </pre></code> will evaluate <code>condition2</code> only if <code>condition1</code> is false. The difference is significant if condition2 is a function or another expression with a side-effect. There is, however, no difference between the <code>||</code> case and the <code>if</code>/<code>else</code> case.
I have seen this once before when one of my models was not mapped correctly (wasn't using nullable types correctly). May you please paste your model and mapping?
This puzzle is explained at [http://www.math.princeton.edu/~wwong/blog/blog200608191813.shtml][1] and that person does a much better job of explaining the problem. The "all prisoners are killed" statement is wrong. The "you can save 30+ on average" is also wrong, the [article][1] says that 30% of the time you can save 100% of the prisoners. If I had more karma, I would vote down this question. [1]: http://www.math.princeton.edu/~wwong/blog/blog200608191813.shtml
One of the common linking errors I've run into is when a function is used differently from how it's defined. If you see such an error you should make sure that every function you use is properly declared in some .h file. You should also make sure that all the relevant source files are compiled into the same lib file. An error I've run into is when I have two sets of files compiled into two separate libraries, and I cross-call between libraries. Is there failure you have in mind?
The name "lambda" is just a historical artifact. All we're talking about is an expression whose value is a function. A simple example (using Scala for the next line) is: args.foreach(arg => println(arg)) where the argument to the `foreach` method is an expression for an anonymous function. The above line is more or less the same as writing something like this (not quite real code, but you'll get the idea): void printThat(Object that) { println(that) } ... args.foreach(printThat) except that you don't need to bother with: 1. Declaring the function somewhere else (and having to look for it when you revisit the code later). 2. Naming something that you're only using once. Once you're used to function values, having to do without them seems as silly as being required to name every expression, such as: int tempVar = 2 * a + b ... println(tempVar) instead of just writing the expression where you need it: println(2 * a + b) The exact notation varies from language to language; Greek isn't always required! ;-)
You should probably target the Windows Mobile platform. The Palm platform is rather archaic and no longer widely used. The development environment is also rather spartan, while Microsoft has full IDEs available for Windows Mobile development. You might also consider the iPhone/iPod touch platform - I have a feeling the number of devices will multiply at an exponential rate and I've heard that developing applications is much easier due to the completeness of the system stack.
The new v8 engine which [should come out][1] today supports it (i think) [1]: http://googleblog.blogspot.com/2008/09/fresh-take-on-browser.html
You can use SQLMetal.exe to generate your dbml and or cs/vb file. Use a pre-build script to start it and target the directory where your datacontext project belongs.
You can use SQLMetal.exe to generate your dbml and or cs/vb file. Use a pre-build script to start it and target the directory where your datacontext project belongs. C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sqlmetal.exe /server:<SERVER> /database:<database> /code:"path\Solution\DataContextProject\dbContext.cs" /language:csharp /namespace:<your namespace>
How do I create a database programatically in SQL Server?
|.net|sql-server|
I would like to create a new database from my C# application. How can I do that? I'm assuming once I create it, I can simply generate a connection string on the fly and connect to it, and the issue all the CREATE TABLE statements.
I'm with @Shaun Austin - try wrapping the try with the fully qualified name catch (System.Exception) and see if that helps.Does the ANTLR doc say what Exceptions should be thrown?
There is a tool in Ant called a classfileset. You specify the list of root classes that you know you need, and then the classfileset recursively analyzes their code to find all dependencies. Alternatively, you could develop a good test suite that exercises all of the functions that you need, then run your tests under a test coverage tool. The tool will tell you which classes (and statement in them) were actually utilized. This could give you an even smaller set of code than what you'd find with static analysis.
You should probably at least evaluate the Apple [iPod Touch][1]. It certainly meets your basic "touch screen + WiFi" spec, and your users presumably won't object to all the the other nice features that will come along for the ride. I don't know what your cutoff for "cheap" is, but $299 for the base model seems pretty reasonable for a high-quality touch screen and WiFi in a pocketable device. [1]: http://www.apple.com/ipodtouch/
[KB307283][1] explains how to create a database using ADO.NET. From the article: String str; SqlConnection myConn = new SqlConnection ("Server=localhost;Integrated security=SSPI;database=master"); str = "CREATE DATABASE MyDatabase ON PRIMARY " + "(NAME = MyDatabase_Data, " + "FILENAME = 'C:\\MyDatabaseData.mdf', " + "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " + "LOG ON (NAME = MyDatabase_Log, " + "FILENAME = 'C:\\MyDatabaseLog.ldf', " + "SIZE = 1MB, " + "MAXSIZE = 5MB, " + "FILEGROWTH = 10%)"; SqlCommand myCommand = new SqlCommand(str, myConn); try { myConn.Open(); myCommand.ExecuteNonQuery(); MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (System.Exception ex) { MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { if (myConn.State == ConnectionState.Open) { myConn.Close(); } } [1]: http://support.microsoft.com/kb/307283
There are some libraries, such as MDB2 in PEAR that make querying a bit easier and safer. Unfortunately, they can be a bit wordy to set up, and you sometimes have to pass them the same info twice. I've used MDB2 in a couple of projects, and I tended to write a thin veneer around it, especially for specifying the types of fields. I generally make an object that knows about a particular table and its columns, and then a helper function in that fills in field types for me when I call an MDB2 query function. For instance: function MakeTableTypes($TableName, $FieldNames) { $Types = array(); foreach ($FieldNames as $FieldName => $FieldValue) { $Types[] = $this->Tables[$TableName]['schema'][$FieldName]['type']; } return $Types; } Obviously this object has a map of table names -> schemas that it knows about, and just extracts the types of the fields you specify, and returns an matching type array suitable for use with an MDB2 query. MDB2 (and similar libraries) then handle the parameter substitution for you, so for update/insert queries, you just build a hash/map from column name to value, and use the 'autoExecute' functions to build and execute the relevant query. For example: function UpdateArticle($Article) { $Types = $this->MakeTableTypes($table_name, $Article); $res = $this->MDB2->extended->autoExecute($table_name, $Article, MDB2_AUTOQUERY_UPDATE, 'id = '.$this->MDB2->quote($Article['id'], 'integer'), $Types); } and MDB2 will build the query, escaping everything properly, etc. I'd recommend measuring performance with MDB2 though, as it pulls in a fair bit of code that might cause you problems if you're not running a PHP accelerator. As I say, the setup overhead seems daunting at first, but once it's done the queries can be simpler/more symbolic to write and (especially) modify.
There are some libraries, such as MDB2 in PEAR that make querying a bit easier and safer. Unfortunately, they can be a bit wordy to set up, and you sometimes have to pass them the same info twice. I've used MDB2 in a couple of projects, and I tended to write a thin veneer around it, especially for specifying the types of fields. I generally make an object that knows about a particular table and its columns, and then a helper function in that fills in field types for me when I call an MDB2 query function. For instance: function MakeTableTypes($TableName, $FieldNames) { $Types = array(); foreach ($FieldNames as $FieldName => $FieldValue) { $Types[] = $this->Tables[$TableName]['schema'][$FieldName]['type']; } return $Types; } Obviously this object has a map of table names -> schemas that it knows about, and just extracts the types of the fields you specify, and returns an matching type array suitable for use with an MDB2 query. MDB2 (and similar libraries) then handle the parameter substitution for you, so for update/insert queries, you just build a hash/map from column name to value, and use the 'autoExecute' functions to build and execute the relevant query. For example: function UpdateArticle($Article) { $Types = $this->MakeTableTypes($table_name, $Article); $res = $this->MDB2->extended->autoExecute($table_name, $Article, MDB2_AUTOQUERY_UPDATE, 'id = '.$this->MDB2->quote($Article['id'], 'integer'), $Types); } and MDB2 will build the query, escaping everything properly, etc. I'd recommend measuring performance with MDB2 though, as it pulls in a fair bit of code that might cause you problems if you're not running a PHP accelerator. As I say, the setup overhead seems daunting at first, but once it's done the queries can be simpler/more symbolic to write and (especially) modify. I think MDB2 should know a bit more about your schema, which would simpify some of the commonly used API calls, but you can reduce the annoyance of this by encapsulating the schema yourself, as I mentioned above, and providing simple accessor functions that generate the arrays MDB2 needs to perform these queries. Of course you can just do flat SQL queries as a string using the query() function if you want, so you're not forced to switch over to the full 'MDB2 way' - you can try it out piecemeal, and see if you hate it or not.
Whats the value for the SqlException.ErrorCode property? Can you work with that? Seems like [this guy](http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1919880&SiteID=1&pageid=0) is having timeouts, may be worth checking the code for **-2146232060**. I would set this up as a static const in your data code.
The interesting question, should you decide to log to the database, is where do you log database connection errors? If I'm logging to a database, I always have a secondary log location (file, event log, etc) in case there are communication errors. It really does make it easier to diagnose issues later on.
I prefer keeping all data **access** logic in the program code, in which the data access layer executes straight SQL queries. On the other hand, data **management** logic I put in the database in the form of triggers, stored procedures, custom functions and whatnot. An example of something I deem worthy of database-ifying is data generation - assume our customer has a FirstName and a LastName. Now, the user interface needs a DisplayName, which is derived from some nontrivial logic. For this generation, I create a stored procedure which is then executed by a trigger whenever the row (or other source data) is updated. There appears to be this somewhat common misunderstanding that the data access layer IS the database and everything about data and data access goes in there "just because". This is simply wrong but I see a lot of designs which derive from this idea. Perhaps this is a local phenomonon, though. I may just be turned off the idea of SPs after seeing so many badly designed ones. For example, one project I participated in used a set of CRUD stored procedures for every table and every possible query they encountered. In doing so they simply added another completely pointless layer. It is painful to even think about such things.
I've used [Bakefile][1] before with some success. It's fairly simple and seems to work well. [1]: http://www.bakefile.org/index.html
These days I hardly ever use stored procedures. I only use them for complicated sql queries that can't easily be done in code. One of the main reasons is because stored procedures do not work as well with OR mappers. These days I think you need a very good reason to write a business application / information system that does not use some sort of OR mapper.
[Source][1] for Matt's answer. I can get it to run by double-clicking a file by creating a batch file with the following in it: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe LocationOfPS1File [1]: http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/run.mspx#ECEAC
Maybe the [Jack][1] sourcecode may help too. It's a sound driver for Posix compatible systems with a lot of possibilites and supports USB and Firewire audio devices. [1]: http://jackaudio.org/
Suppress NTLM dialog box after unauthorized request
|asp.net|javascript|sharepoint|
In a recent sharepoint project, I implemented an authentication webpart which should replace the NTLM authentication dialog box. It works fine as long as the user provides valid credentials. Whenever the user provides invalid credentials, the NTLM dialog box pops up in Internet Explorer. My javscript code which does the authentication via XmlHttpRequest looks like this: function Login() { var request = GetRequest(); // retrieves XmlHttpRequest request.onreadystatechange = function() { if (this.status == 401) { // unauthorized request -> invalid credentials // do something to suppress NTLM dialog box... // already tried location.reload(); and window.location = <url to authentication form>; } } request.open("GET", "http://myServer", false, "domain\\username", "password"); request.send(null); } I don't want the NTLM dialog box to be displayed when the user provides invalid credentials. Instead the postback by the login button in the authentication form should be executed. In other words, the browser should not find out about my unauthorized request. Is there any way to do this via Javascript?
A quick google search gave me this forum <http://board.flashkit.com/board/showthread.php?t=715062> where they state that Flash is unable to handle 5.1 audio and the alternative is to use another application that can communicate with Flash to handle the audio side of things. I also found this blog entry from Summit Projects <http://summitprojectsflashblog.wordpress.com/2008/08/07/wave-theory-in-actionscript-3-part-4/> where they go into great detail about byte handling and processing audio samples. I'm not sure if they are using their own actionscript libraries for this, or if they are using Adobe's libraries. I'm not too up to speed on the audio side of Flash with respects to surround sound. I think your two options might have to be either using a separate application to run your audio(which may be less stressful) or maybe getting in touch with the Summit people if you are as lost as I am over some of the concepts they touch on, heh. Good luck!
Tools for finding memory corruption in managed c++ code?
|.net|managed-c++|
I have a .NET application, which is using an open source C++ compression library for compressing images. We are accessing the C++ library via managed C++. I'm seeing heap corruption during compression. A call to _CrtIsValidHeapPointer is finding an error on a call to free() when cleaning up after compression. My question is, are there tools such as Purify to help diagnosis this problem and what is causing the heap corruption when working in a combination of managed and unmanaged code? I do have the exception caught in the debugger, but it would be nice to have other tools to help find the solution to the problem.
<a href="http://www-01.ibm.com/software/awdtools/purifyplus/win/">Rational Purify for Windows</a> supports .NET, so I guess that could be used?
Finding your own number in a box
|puzzle|algorithm|
100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100. One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly permuted!). Once inside room B, each prisoner gets to open 50 boxes (he chooses which one he opens). If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed. Before entering room B, the prisoners can agree on a strategy (algorithm). There is no way to communicate between rooms (and no message can be left in room B!). Find a strategy (algorithm) that maximizes the probability that all prisoners survive. What probability does your algorithm achieve?
100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100. One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly permuted!). Once inside room B, each prisoner gets to open 50 boxes (he chooses which one he opens). If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed. Before entering room B, the prisoners can agree on a strategy (algorithm). There is no way to communicate between rooms (and no message can be left in room B!). Find a strategy (algorithm) that maximizes the probability that all prisoners survive. What probability does your algorithm achieve? Edit: Note that I did ask if it was OK to post puzzles. I'd like to get some feedback from people downvoting if possible!
I use message flags for my "action folders" and shunt everything into one big Archive folder after I process it (use the Ctrl+Shift+V shortcut to do this). As an example, I might flag a received message with a red flag (reply), a blue flag (pending, meaning I have to do something about it first), or maybe a green flag (reference). I then have search folders for each of my flag colors. This flagging/search folder method is explained fairly well in [this blog post][1]. I've also implemented a [Gmail-like conversation view][2] search folder which has been pretty handy. [1]: http://samkale.wordpress.com/2008/08/19/adapting-the-google-foo-email-tips-for-the-outlook-bound/ [2]: http://danbrettsblog.blogspot.com/2006/05/give-outlook-gmail-conversation-view.html
Why is the subprocess.Popen class not named Subprocess?
|python|subprocess|
The primary class in the `subprocess` module is name `Popen`, and represents a subprocess. `Popen` sounds like someone was trying to force the name to follow some function naming format, rather than chosing a name that actually represents what the object is. Does anyone know why it was chosen over something simple like, say, `Subprocess`?
Detecting font in javascript
|javascript|css|
Suppose I have the following css rule in my html <pre>body { font-family:Calibri,Trebuchet MS,Helvetica,sans-serif; }</pre> How can I detect which one of the defined fonts was used in the user's browser?
|javascript|css|font|
Suppose I have the following css rule in my html <pre>body { font-family:Calibri,Trebuchet MS,Helvetica,sans-serif; }</pre> How can I detect which one of the defined fonts was used in the user's browser? Edit for people wondering why I want to do this: The font I am detecting contains glyphs not available in other fonts and when the user does not have it I want to display a link asking the user to download that font so they can use my web app. Currently I am displaying the download font link for all users, now I can only display it for people who do not have the correct font installed.
|javascript|css|fonts|
|javascript|html|css|fonts|
Why does this C code produce a double instead of a float?
|c|types|
<code>celsius = (5.0/9.0) * (fahr-32.0);</code> Is it just a development choice that the C developers decided upon or is there a reason to this? I believe a float is smaller than a double, so it might be to prevent overflows caused by not knowing what decimal format to use. Is that the reason, or am I overlooking something?
In bash: if ps aux | grep really_long_script.rb | grep -vq grep then echo Script already running else ruby really_long_script.rb fi
It depends a _lot_ on the database you're using as a back-end. I've had [rather terrible experiences with MySQL as a back-end](http://stackoverflow.com/questions/5842/issues-using-ms-access-as-a-front-end-to-a-mysql-database-back-end#9200). Make sure the ODBC link you're using is actively developed, stable and complete --- this was definitely not the case for MySQL. You may also want to check for any compatibility issues between Access and Postgre. And, of course, it won't hurt to test extensively. Oh, and I think it'd be absolutely great if you could post back here later with your experiences!
Interesting. I don't know, but I did try this: >>> now = time.mktime((2008, 8, 22, 11 ,17, -1, -1, -1, -1)) >>> tomorrow = time.mktime((2008, 8, 23, 11 ,17, -1, -1, -1, -1)) >>> tomorrow - now 86400.0 which is what you expected. My guess? Maybe some time correction was done since the epoch. This could be only a few seconds, something like a leap year. I think I heard something like this before, but can't remember exactly how and when it is done...
Short answer: Because of timezones. The Epoch is in UTC. For example, I'm on IST (Irish Stsandard Time) or GMT+1. time.mktime() is relative to my timezone, so on my system this refers to >>> time.mktime((2009, 1, 31, 0, 0, 0, 5, 31, -1)) 1233360000.0 Because you got the result 1233378000, that would suggest that you're 5 hours behind me >>> (1233378000 - 1233360000) / (60*60) 5 Have a look at the time.gmtime() function which works off UTC.
- Click on the web site node in the solution explorer. - Press F4 to see the properties window. - Change the virtual path from **/projectname** to **/**
- Click on the web site node in the solution explorer. - Press F4 to see the properties window. - Change the virtual path from **/projectname** to **/** Bear in mind that this has an impact on how you expect the application/web site to be deployed. If it is ever used outside the root of a web server, the URL paths will be incorrect.