instruction
stringlengths
0
30k
Simplest way to check if two integers have same sign?
|integer|bit-manipulation|sign|
Which is the simplest way to check if two integers have same sign? Is there any short bitwise trick to do this?
Here is how: import gobject class MyGObjectClass(gobject.GObject): ... gobject.signal_new("signal-name", MyGObjectClass, gobject.SIGNAL_RUN_FIRST, None, (str, int)) Where the second to last argument is the return type and the last argument is a tuple of argument types.
As far as I know, you can't unless you're root or have sudo set up to allow you to switch users. Or, you can have your executable have the suid bit set up on it, and have it owned by nobody. But that requires root access too.
Well, I'll speak a little bit about Windows. The C functions exported from DLLs do not contain information about the types, names, or number of arguments -- nor do I believe you can determine what the calling convention is for a given function. For comparison, take a look at National Instrument's LabVIEW programmin...
Well, I'll speak a little bit about Windows. The C functions exported from DLLs do not contain information about the types, names, or number of arguments -- nor do I believe you can determine what the calling convention is for a given function. For comparison, take a look at National Instrument's LabVIEW programmin...
I am not clear on what qualifies as a single uniform report in your book but here is what I do. I use Maven2 for builds and with it you can configure a series of reporting plugins (including PMD, CPD, checkstyle, coberturba, etc). Maven will also auto-generate a website (site plugin) for your project which contains...
Best way of store only date on datetime field?
|database|t-sql|
Scenario: A stored procedure receives from code a DateTime with, let's say DateTime.Now value, as a datetime parameter. The stored procedure needs to store only the date part of the datetime on the row, but preserving all date related arithmetics for, to say, do searches over time intervals and doing reports based ...
Your question is unclear, are you trying to encode something? If so [**utf8_encode**][1] is your friend. Are you trying to determine if it doesn't need to be encoded? If so, **utf8_encode** is still your friend, because you can check that the result is the same as the input! [1]: http://us2.php.net/manual/en/...
From: [Developer Connection - Indirect Addressing](http://developer.apple.com/documentation/developertools/conceptual/MachOTopics/Articles/indirect_addressing.html#//apple_ref/doc/uid/TP40004919-DontLinkElementID_3) Indirect addressing is the name of the code generation technique that allows symbols defined in one f...
If you build your project with Maven, and you have those tools "plugged in" to your Maven build, then the Maven report that is generated for the build will include the output of those static analysis tools.
Visual Studio opens default browser instead of IE
Add "-Dlog4j.debug" to the command line and there will be extra info in standard output about how it is configured.
There is [**CUnit**][1] And [**Embedded Unit**][2] is unit testing framework for Embedded C System. Its design was copied from JUnit and CUnit and more, and then adapted somewhat for Embedded C System. Embedded Unit does not require std C libs. All objects are allocated to const area. And [**Tessy**][3] automates...
The depression in the responses is overwhelming... But don't fear, we've got [the holy book to exorcise the demons of legacy C++ code][1]. Seriously just buy the book if you are in line for more than a week of jousting with legacy C++ code. Turn to page 127: **The case of the horrible include dependencies.** (Now I ...
The book [Foundations of Multidimensional and Metric Data Structures][1] can help you decide which data structure is fastest for range queries: octrees, kd-trees, R-trees, ... It also describes data layouts for keeping points together in memory. [1]: http://www.amazon.com/dp/0123694469
If you are working on the Microsoft platform, you should be able to use the Win32 API in Ruby to call GetFileVersionInfo(), which will return the information you're looking for. [http://msdn.microsoft.com/en-us/library/ms647003.aspx][1] [1]: http://msdn.microsoft.com/en-us/library/ms647003.aspx
The sample code already provided is good but I also do it this way and just get the hierarchical name of the server: Set s = New NotesSession Set db = s.CurrentDatabase If db.Server <> "" Then Set sName = New NotesName(db.Server) Else Set sName = New NotesName(s.Username) End ...
For scripts, I always use _ksh_ because it smooths over [gotchas](http://stackoverflow.com/questions/2732/shell-scripting-input-redirection-oddities#12412). But I find _bash_ more comfortable for interactive use. For me the _emacs_ key bindings and tab completion are the main benefits. But that's mostly force of h...
You can also call into unmanaged code via P/Invoke. This may be easier if your code doesn't currently use COM. I guess you would probably need to write some specific export points in your code using "C" bindings if you went this route. Probably the biggest thing you have to watch out for in my experience is that the...
This is kind of hacking eclipse and you can get into trouble doing this but this should work: Open the navigator view and find that there is a .settings folder under your project expand it and then open the file: org.eclipse.wst.common.project.facet.core.xml you should see a line that says: <installed facet="jst.web...
This is kind of hacking eclipse and you can get into trouble doing this but this should work: Open the navigator view and find that there is a .settings folder under your project expand it and then open the file: org.eclipse.wst.common.project.facet.core.xml you should see a line that says: <code> &lt;install...
There's a series of articles on CodeProject that details writing Shell Extensions and is very good: http://www.codeproject.com/KB/shell/shellextguide1.aspx
SMTP/POP3 can be enabled on the Domino server. Worked with this before and gotten Squirrel Mail running with it. SMTP is a bit resource intensive, but well worth the effort because then you don't have to descend into LotusLand to get things working. Just write a small Java CLI program that will check a specific email...
|visual-studio|
When I debug in Visual Studio, firefox opens and that is annoying because of the hookups that IE and VS have such as when you close the IE browser that starting debug opened, VS stops debugging. How can I get Visual Studio to open IE instead without having to set IE as my default browser?
How to Truncate a string in PHP to the word closest to a certain number of characters?
|php|string|function|
I have a code snippet written in PHP that pulls a block of text from a database and sends it out to a widget on a webpage. The original block of text can be a lengthy article or a short sentence or two; but for this widget I can't display more than, say, 200 characters. I could use substr() to chop off the text at 20...
store the date with time = midnight EDIT: i was assuming MS SQL Server
Right-click on an aspx file and choose 'browse with'. I think there's an option there to set as default.
Scott Guthrie has made a post on [how to change Visual Studio's default browser][1]: > 1) Right click on a .aspx page in your > solution explorer > > 2) Select the "browse with" context > menu option > > 3) In the dialog you can select or add > a browser. If you want Firefox in the > list, click "add" and...
In the Solution Explorer, right-click any ASPX page and select "Browse With" and select IE as the default. Note... the same steps can be used to add Google Chrome as a browser option and to optionally set it as the default browser.
function holdit(btn, action, start, speedup) { var t; var repeat = function () { action(); t = setTimeout(repeat, start); start = start / speedup; } btn.mousedown = function() { repeat(); } ...
The checksum and contract ideas are good for preventing the "problems" you describe, but if the cost to you is the difficulty of rolling-out upgrades and bug-fixes, how are your clients making changes that don't pass the <b>comprehensive test suite</b>? If they are capable of making these changes (or at least, making ...
The depression in the responses is overwhelming... But don't fear, we've got [the holy book to exorcise the demons of legacy C++ code][1]. Seriously just buy the book if you are in line for more than a week of jousting with legacy C++ code. Turn to page 127: **The case of the horrible include dependencies.** (Now I ...
2 ways that I know of : **USING PPM :** With **Windows** (ActivePerl) I've used ppm from the command line type ppm. At the ppm prompt ... ppm> install foo or ppm> search foo to get a list of foo modules available. Type **help** for all the commands **USING CPAN :** you can also use ...
In my WPF application, I have a number of databound TextBoxes. The `UpdateSourceTrigger` for these bindings is `LostFocus`. The object is saved using the File menu. The problem I have is that it is possible to enter a new value into a TextBox, select Save from the File menu, and never persist the new value (the one vis...
In my WPF application, I have a number of databound TextBoxes. The `UpdateSourceTrigger` for these bindings is `LostFocus`. The object is saved using the File menu. The problem I have is that it is possible to enter a new value into a TextBox, select Save from the File menu, and never persist the new value (the one vis...
In my little application I have at least a million files weighing in at about 200GB at last count. All the files are sitting in an XFS file system mounted on a linux server over iscsi. The paths are stored in the database. use some kind of intelligent naming convention for your file paths and file names. IMHO, use t...
[Minuit][1] is an incredibly simple unit testing framework. I'm using it to unit test c microcontroller code for avr. [1]: http://www.jera.com/techinfo/jtns/jtn002.html
I'd recommended w3schools.com. It's a pretty good and comprehensive library, I find.
A simple solution is to use a 64 bit integer where the lower 16 bits is the first vertex coordinate, next 16 bits is the second, and so on. This will be unique for all your vertices, though not very compact. So here's some half-assed code to do this. Hopefully I got the casts right. uint64_t generateId( uint1...
A simple solution is to use a 64 bit integer where the lower 16 bits is the first vertex coordinate, next 16 bits is the second, and so on. This will be unique for all your vertices, though not very compact. So here's some half-assed code to do this. Hopefully I got the casts right. uint64_t generateId( uint1...
For a typical CMM level 1 programming shop, making the effort to get to level 2 is worthwhile; this means that you need to think about you processes and write them down. Naturally, this will meet resistance from cowboy programmers who feel limited by standards, documentation, and test cases. The effort to get from ...
**It will take some *training* and some *time* to learn the style needed to develop maintainable code**. Coming from Java/C#/C++, you probably have a good idea of good software architecture. Now you just need to learn the peculiarities of LabView and the common pitfalls. For the basics, National Instruments offer...
I have used [this help file][1] in the past. Very good resource [1]: http://www.majorgeeks.com/Mystery_Behind_Windows_Registry_d415.html
You shouldn't do any threading from ASP.NET pages. Any thread that is long running is in danger of being killed when the worker process recycles. You can't predict when this will happen. Any long-running processes need to be handled by a windows service. You can kick off these processes by dropping a message in MSM...
This is what I used: using System; using System.Diagnostics; using System.Web; ... // settings string PortNumber = "1162"; // arbitrary unused port # string LocalHostUrl = string.Format("http://localhost:{0}", PortNumber); string PhysicalPath = Environment.CurrentDire...
This is what I used that worked: using System; using System.Diagnostics; using System.Web; ... // settings string PortNumber = "1162"; // arbitrary unused port # string LocalHostUrl = string.Format("http://localhost:{0}", PortNumber); string PhysicalPath = Environment...
What you need to use for this scenario is Asynchronous Pages, a feature that was added in ASP.NET 2.0 > Asynchronous pages offer a neat > solution to the problems caused by > I/O-bound requests. Page processing > begins on a thread-pool thread, but > that thread is returned to the thread > pool once an asynchro...
Most payment gateways provide such numbers for testing their services, but they will generally only work on the staging/test versions of those gateways.
if (x * y) > 0... assuming non-zero and such.
Given that the use of the shuffle function is forbidden, I would use $keys = array_rand($myArray, count($myArray)) to return an array of the keys from $myArray in random order. From there it should be simple to reassemble them into a new array that has been randomized. Something like: $keys = array_rand($myArra...
Short Answer: PHP's array_rand() function Given that the use of the shuffle function is forbidden, I would use $keys = array_rand($myArray, count($myArray)) to return an array of the keys from $myArray in random order. From there it should be simple to reassemble them into a new array that has been randomized. Somet...
C# (the .NET framework in general, as far as I know) doesn't support parametrized enums like Java does. That being said, you might want to look at Attributes. Some of the features that Java enums are capable of are somewhat doable through Attributes.
The Microsoft forum has the following code snipit to delete the certificates: use msdb BEGIN TRANSACTION declare @sp sysname declare @exec_str nvarchar(1024) declare ms_crs_sps cursor global for select object_name(crypts.major_id) from sys.crypt_properties crypts, sys.certificates cert...
We used BizTalk for a couple of years, but gave it up for our own custom framework that allowed more flexibility.
I have a lot of friends who swear by CMake for cross-platform development: [http://www.cmake.org/][1] It's the build system used for [VTK][2] (among other things), which is a C++ library with cross-platform Python, Tcl, and Java bindings. I think it's probably the least complicated thing you'll find with that ma...
An enum in C++ can be any integral type. You can, for example, have an enum of chars. IE: enum MY_ENUM { CHAR_VALUE = 'c', }; I would *assume* this includes __int64. Try just enum MY_ENUM { LARGE_VALUE = 0x1000000000000000, };
An enum in C++ can be any integral type. You can, for example, have an enum of chars. IE: enum MY_ENUM { CHAR_VALUE = 'c', }; I would *assume* this includes __int64. Try just enum MY_ENUM { LARGE_VALUE = 0x1000000000000000, }; According to my commenter, sixlett...
How do I TDD a custom membership provider and custom membership user?
|c#|asp.net|authentication|
I need to create a custom membership user and provider for an ASP.NET mvc app and I'm looking to use TDD. I have created a User class which inherits from the MembershipUser class, but when I try to test it I get an error that I can't figure out. How do I give it a valid provider name? Do I just need to add it to web...
SELECT id, datefield, count(*) FROM tablename GROUP BY datefield HAVING count(*) > 1
group by with having is your friend: select id, count(*) from records group by date having count(*) > 1
Sparse indexing for those with lots of NULL's. Also the DATETIME2 data type that alot of people have waiting for 0001-01-01 through 9999-12-31.
You're describing P/Invoke. That means your C++ library will need to expose itself via a DLL interface, and the interface will need to be simple enough to describe to P/Invoke via the call attributes. When the managed code calls into the unmanaged world, the parameters have to be marshalled, so it seems there could b...
In a LotusScript Agent how do you get the name of the current server?
|domio|lotus|lotusscript|
In a LotusScript Agent that is being run via WebQueryOpen, how do you get the name of the current server?
|lotusscript|lotus-domino|lotus|
The performance advantages of MyISAM are actually pretty minimal in some cases; you need to benchmark your own application MyISAM vs InnoDB. Using the InnoDB transactional engine exclusively gives other benefits too. In my testing InnoDB will use up typically about 150% more disc space than MyISAM- this is because o...
**It will take some *training* and some *time* to learn the style needed to develop maintainable code**. Coming from Java/C#/C++, you probably have a good idea of good software architecture. Now you just need to learn the peculiarities of LabView and the common pitfalls. For the basics, National Instruments offer...
Let's be careful with our definitions here - An *Emacs copy* is the command `kill-ring-save` (usually bound to `META-W`). - A *system copy* is what you typically get from pressing CTRL-C (or choosing "Edit->Copy" in a application window). - An *X copy* is "physically" highlighting text with the mouse cursor....
Let's be careful with our definitions here - An *Emacs copy* is the command `kill-ring-save` (usually bound to `META-W`). - A *system copy* is what you typically get from pressing CTRL-C (or choosing "Edit->Copy" in a application window). - An *X copy* is "physically" highlighting text with the mouse cursor....
I don't think unmanaged switches/hubs will have arp entries - being transparent at the mac layer is their reason for existing. The best idea I can come up with is to pingflood each internal IP in turn, and then while that's going on, try and ping all the other IPs. This will help because you'll only get decent respon...
I don't think unmanaged switches/hubs will have arp entries - being transparent at the mac layer is their reason for existing. And I don't think there's a way to get their MAC forwarding tables short of taking them apart and finding a JTAG or other port to talk to them with, which is unlikely to be feasible. Th...
You can try my fixed point class from here: http://www.codef00.com/projects/Fixed.h It is designed to be a near drop in replacement for floats/doubles and has a choose-able precision. It does make use of boost to add all the necessary math operator overloads, so you will need that as well (I believe for this it is j...
You can try my fixed point class from here: http://www.codef00.com/projects/Fixed.h It is designed to be a near drop in replacement for floats/doubles and has a choose-able precision. It does make use of boost to add all the necessary math operator overloads, so you will need that as well (I believe for this it is j...
There is on Linux/Unix: <a href="http://sourceforge.net/projects/x11guitest">http://sourceforge.net/projects/x11guitest</a> I'm not familiar of anything similar for Windows or Mac that uses perl.
If you are getting thrown off by the fact that the user/group is listed as having "Limited Access" on the ACLs on, say, the parent site/web. That's just a placeholder SharePoint uses to make sure people have access to at least the bare minimum set of objects (e.g. theme and other UI files and the parent web itself) to...
Can you just change your success function to reset the selected item to the first option? $("#Products").append(result).selectedIndex = 0; or to set it to the previous selection? var tmpIdx = $("#Products").selectedIndex; $("#Products").append(result).selectedIndex = tmpIdx; If the onChange eve...
[django-command-extensions][1] is a django library that gives some extra commands to manage.py. One of them is sqldiff, which should give you the sql needed to update to your new model. It is, however, listed as 'very experimental'. [1]: http://code.google.com/p/django-command-extensions/
If you only care about supporting Windows and don't mind the time it takes to learn it, go with WPF. It's fast, flexible, easy to reskin, and has great tools to work with it.
Best way to send an email from a .NET application?
|.net|vb.net|email|
I'm working on a Windows Forms (.NET 3.5) application that has a built-in exception handler to catch any (heaven forbid) exceptions that may arrise. I'd like the exception handler to be able to prompt the user to click a "Send Error Report" button, which would then cause the app to send an email to my FogBugz email add...
The behavior you describe is allowed. How is the code making the schema changes? Building SQL on the fly and executing through an ADO Command? Or using ADOX? If you have access to the database server, try running a SQL Profiler trace while testing the scenario you outlined. See if the trace logs any errors/rollb...
I think it is worth learning WPF. Once you are up to speed, design work on your forms is much easier IMHO. I wouldn't worry as much about the 'sexy' stuff. Most of this is just a fad. You can make 'normal' Winforms-style applications very quickly and easy in WPF. The whole concept lends itself to easier design IMO.
You can just add a row which comes before your set of data, for each field you want to total just give that cell an expression which does a SUM() of that particular field.
Top ten ordering in Excel based on complex team rules
|excel|spreadsheet|
I have an excel spreadsheet in a format similar to the following... | NAME | CLUB | STATUS | SCORE | | Fred | a | Gent | 145 | | Bert | a | Gent | 150 | | Harry | a | Gent | 195 | | Jim | a | Gent | 150 | | Clare | a | Lady | 99 | | Simon | ...
As ugly as it is, calling out to `printf(1)` is the common solution. A cleaner, though somewhat more complex, solution is to use AppleScript Studio, which allows you to call into Objective-C objects/classes from your AppleScript code with the `call method` syntax documented [here][1]. With that, you'd be able to ...
When browsers treat the markup as XML: <script> <![CDATA[ ...code... ]]> </script> When browsers treat the markup as HTML: <script> ...code... </script> When browsers treat the markup as HTML and you want your XHTML 1.0 markup (for example) to validate. <...
Some of the GNOME projects have been migrating to [waf][1]. It's Python-based, like Scons, but also standalone -- so rather than require other developers to have your favorite build tool installed, you just copy the standalone build script into your project. [1]: http://code.google.com/p/waf/