instruction stringlengths 0 30k ⌀ |
|---|
One way to do this is to repeatedly update the line of text with the current progress. For example:
def status(percent):
sys.stdout.write("%3d%%\r" % percent)
sys.stdout.flush()
Note that I used `sys.stdout.write` instead of `print` (this is Python) because `print` automatically prints "\r\n... |
You use bitwise operations. The pseudo-code would be something like:
bool HasPermission(User user, Permission permission) {
return (user.Permission & permission) != 0;
}
void SetPermission(User user, Permission permission) {
user.Permission |= permission;
}
void... |
Tool to view the contents of the Solution User Options file (.suo) |
|visual-studio|suo| |
Are there any free tools available to view the contents of the solution user options file (the .suo file that accompanies solution files)?
I know it's basically formatted as a file system within the file, but I'd like to be able to view the contents so that I can figure out which aspects of my solution and customiza... |
|visual-studio|projects-and-solutions|suo| |
the design is all wrong. You should have single table, with parent child relationship (literrally).
Then you can figure out uncles (and aunts) with a query
<code>
select id from persons where -find all children of the grandparents
parent id in (
select parentid from persons --find the grandparents
... |
In [Clean Code][1], page 124, [Robert C. Martin][2] writes:
> The moral of the story is simple: *Test code is just as important as production code.* It is not a second-class citizen. It requires thought, design, and care. It must be kept as clean as production code.
[1]: http://amazon.com/o/ASIN/0132350882
[... |
@nickf: Here is the PHP function in C#:
public static string Ordinal(int number)
{
string suffix = String.Empty;
int ones = number % 10;
int tens = (int)Math.Floor(number / 10M) % 10;
if (tens == 1)
{
suffix = "th";
}
else
{
switch (ones)
{
case 1:
suffix ... |
You should be able to reprogram most of the python scripts available to generate terrain for rendering to generate terrain for your game... is there a specific thing you *need* from the script to make it suitable for realtime gameplay instead of a static render? |
Zend PHP debugger: How can I start debugging a page using a get argument? |
|php|debugging|zend| |
I am trying out the debugger built into Zend studio. It seems great! One thing though, when I start a page using the debugger does anyone know how I can set a request get argument within the page?
For example, I don't want to debug runtests.php
I want to debug runtests.php?test=10
I assume its a simple confi... |
Tracking CPU and Memory usage per process |
|windows|system-administration|process-management| |
I suspect that one of my applications eats more CPU cycles than I want it to. The problem is - it happens in bursts, and just looking at the task manager doesn't help me as it shows immediate usage only.
Is there a way (on Windows) to track the history of CPU & Memory usage for some process. E.g. I will start tracki... |
It's definitely more a quiz rather than a real problem. However, if we are allowed to make some assumption, it can be solved in O(1) time. To do it, the strictures the list points to must be copyable. The algorithm is as the following:
We have a list looking like: ... -> Node(i-1) -> Node(i) -> Node(i+1) -> ... and ... |
I would say, that using multiple canvases is generally bad design. On some phones it will even crash. The best way would really be using one canvas with tracking state of the application. And then in paint method you would have
protected void paint(final Graphics g) {
if(menu) {
paintMenu(g);
... |
If you really need to load that form via AJAX you could to do all the Javascript stuff in $.ajax callback itself.
So, you load the popup form like this:
$.ajax({
//...
success: function(text) {
// insert text into container
// the code from $(function() {});
}
... |
What's the purpose of the GtkWidget.events property for (like) GtkTreeView widgets? |
|linux|gtk|pygtk|glade| |
I have a Glade GUI description file with a `GtkTreeView` in a `GtkHBox` in a window; and there's a handler for the `row_activated` signal. Now, Glade has automatically set the "events" property (inherited from `GtkWidget`) of that treeview to some value (`GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUT... |
Directly from the Unit Test FactorySupportTestCase (which are your friends):
[Test]
public void FactorySupport_UsingProxiedFactory_WorksFine()
{
container.AddFacility("factories", new FactorySupportFacility());
container.AddComponent("standard.interceptor", typeof(StandardInterceptor));
contain... |
Just a formal answer:
var i = 0;
while (i < 1) {
do something...
if (i < 1) i = 0;
else i = fooling_function(i); // must return 0
}
I think no browser would detect such things.
|
How to eliminate flicker in Windows.Forms custom control when scrolling? |
|gdi+|.net|c#| |
I want to create a custom control in C#. But every time I have to fully redraw my control, it flickers, even if I use double buffering (drawing to an Image first, and blitting that).
How do I eliminate flicker when I have to fully redraw? |
|c#|.net|winforms|gdi+| |
there is the excellent open source 3d engine called jMonkey (http://www.jmonkeyengine.com) which is being used for a few commercial projects as well as hobby developers...
there is also at a lower level the lwjgl library which jmonkeyengine is built on which is a set of apis to wrap opengl as well as provide other gam... |
Almost every commercial license system has been cracked, we have used many over the years all eventually get cracked, the general rule is write your own, change it every release, once your happy try to crack it yourself.
Nothing is really secure, ultimately look at the big players Microsoft etc, they go with the mo... |
I've used bounds checking and other dynamic analysis tools, and while the architectures are different it's the code that you're checking - in theory you could run bounds checking on any backend and the result would be the same - the code either steps outside its bounds or it does not.
The only complications are addr... |
Software evaluation licensing |
|sofwarelicensing| |
My company is looking to start distributing some software we developed and would like to be able to let people try the software out before buying. We'd also like to make sure it can't be copied and distributed to our customers' customers.
One model we've seen is tying a license to a MAC address so the software will... |
|licensing| |
The article '[Taming lists][1]' from A List Apart has some good advice on CSS styling for breadcrumbs (look down for the heading 'Breadcrumb Trails').
[1]: http://www.alistapart.com/articles/taminglists/ |
If using Microsoft ASP.NET, there's a built in control: [SiteMapPath][1].
[1]: http://msdn.microsoft.com/en-us/library/x20z8c51.aspx |
I found a few good/bad examples of breadcrumbs [here][1].
Also, there's a blog post about [breadcrumb designs][2].
[1]: http://www.designvsart.com/blog/2008/02/06/good-bread-crumbs-bad-bread-crumbs/
[2]: http://f6design.com/journal/2007/02/09/the-humble-breadcrumb/ |
The company I worked for actually used a [usb dongle][1]. This was handy because:
- Our software was also installed on that USB Stick
- The program would only run if it found the (unique) hardware key (any standard USB key has that, so you don't have to buy something special, any stick will do)
- it was not ... |
For partially partially sighted we need to make sure text is not excessivly small and contrasts the background color substantially. We should also make sure text is resizable by using relative sizing units such as *em*'s rather than absolute units like *px*'s (although, in my opinion, this is becoming less of an issue ... |
**Some properties of great unit tests:**
- When a test fails, it should be immediately obvious where the problem lies. If you have to use the debugger to track down the problem, then your tests aren't granular enough. Having exactly one assertion per test helps here.
- When you refactor, no tests should fail.
... |
Rollover safe timer (tick) comparisons |
|c++|c|timer|rollover| |
I have a counter in hardware that I can observe for timing considerations. It counts miliseconds and is stored in a 16 bit unsigned value. How do I safely check if a timer value has passed a certain time and safely handle the inevitable rollover:
//this is a bit contrived, but it illustrates what I'm trying to d... |
What are some viable alternatives to BizTalk Server? |
|biztalk|opinion|open-source| |
In evaluating different systems integration strategies, I've come across some words of encouragement, but also some words of frustration over BizTalk Server.
What are some pros and cons to using BizTalk Server (both from a developer standpoint and a business user), and should companies also consider open source alt... |
OK,
To answer my own. . .I found that the "Listen" directive in the configuration file had been set to "Listen 80" instead of "Listen localhost: 80".
Also, localhost/htdocs/index.html doesn't work, but localhost/index.html does.
Hopefully this can help someone in the future.
Thanks, Schroeder. |
I don't think this is as easy as others have made it out to be. pwd doesn't work, as the current dir is not necessarily the directory with the script. $0 doesn't always have the info either. Consider the following three ways to invoke a script.
./script
/usr/bin/script
script
In the first and third ways ... |
Least code would be:
>>> s = set([1, 2, 3])
>>> list(s)[0]
1
Obviously this would create a new list which contains each member of the set, so not great if your set is very large. |
I might go something like this:
Create custom (private) types for data structures and put all the related logic in there. Dictionary<string, List<int>> etc.
Make inner functions or properties that guarantee behaviour. If you’re continually checking conditions from a publically accessible property then... |
Actually, this is how we determine authority within a fairly large web application that I'm the DBA for.
If you are going to do something like this, you'll really benefit from having a [numbers table][1]. It will make your calculations much faster.
Our web application then just determines whether or not you've ... |
Actually, this is how we determine authority within a fairly large web application that I'm the DBA for.
If you are going to do something like this, you'll really benefit from having a [numbers table][1]. It will make your calculations much faster.
The basic setup includes the following tables:
1. Groups - ... |
I would say, that using multiple canvases is generally bad design. On some phones it will even crash. The best way would really be using one canvas with tracking state of the application. And then in paint method you would have
protected void paint(final Graphics g) {
if(menu) {
paintMenu(g);
... |
**Accurate Indexing**
With CDT you should be sure to enable the "Full Indexing" option rather than the "Fast Indexing" default. It's not perceptibly slower on modern hardware and it does a much better job. In that vein, you should be sure to enable semantic highlighting. This isn't as important in C/C++ as it is ... |
[High Scalability](http://highscalability.com/) is a good blog for scaling SaaS applications. As mentioned, splitting tables across databases as you suggested is generally a bad idea. But a similar concept is sharding, where you keep the same (or similar) schema, but split the data on multiple servers. For example, ... |
This function isn't built in, but you can set it up so you can press the F5 function key to run the query.
1 - Create a new macro.
2 - Use the menu, View > Macro Names to add the "Macro Names" column to the grid if it's not already showing.
3 - Type this in the "Macro Names" column:
{F5}
4 - In the "Acti... |
When I try the following statement:
Dim result As String = Today()
It gives me today's date, as I'd expect, and I'm running VB2005 on Vista. Can you modify the question with the version of VB you're using? Also, can you try the following statement instead of `Today()` to see it works for you without the excep... |
For cases where you key off of a field in a protocol header to direct you to the next stage of processing for that protocol, arrays of function pointers can be used. You use the value from the protocol header to index into the array and call the function for that protocol.
You __must__ handle all possible values in ... |
Unfortunately the constraint API changed in incompatible ways for custom constraints in 2.4.6. NUnit 2.4.5 and earlier used an IConstraint interface and in 2.4.6 it was changed to a Constraint abstract base class. There was an optional Constraint base class in 2.4.5 and earlier, but the class is not consistent betwee... |
I'm surprised any Scheme system will accept a dot symbol at all. My advice is to use another symbol as (I'm sure you're aware) the dot is a shorthand to represent a pair, and even if you can find a Scheme that will take your code you will likely confuse anyone that has the unfortunate task of actually reading your cod... |
At a previous employer we stored everything necessary to build the application(s) in source control. Spinning up a new build machine was a matter of syncing with the source control and installing the necessary software.
|
Rational and Together/J are best-of-breed products, but expensive.
In my experience, I've enjoyed Eclipse Omondo and Sparx Enterprise Architect. Omondo integrates nicely with Eclipse for code generation, and has a very intuitive feel. However, it is strongly tied to Java. Sparx is a good tool for the price point,... |
I recommend the web service route. It offers a standard interface that can be consumed by other client platforms in the future.
.NET clients interact with Java web services pretty well, though there are some gotchas. The best two technologies available for you for the .NET client are Microsoft Web Service Enhancemen... |
|biztalk|open-source| |
|open-source|biztalk| |
In evaluating different systems integration strategies, I've come across some words of encouragement, but also some words of frustration over BizTalk Server.
What are some pros and cons to using BizTalk Server (both from a developer standpoint and a business user), and should companies also consider open source alt... |
[TextMate's snippets][1] are the most closest match but it is not a cross-platform solution and not for Emacs.
The second closest thing is [yasnippet][2] ([screencast][3] shows main capabilities). But it interferes with `hippie-expand` package in my setup and the embedded language is EmacsLisp which I'm not comforta... |
Just check if ms_timer < last_print_time and if so add 2^16 no? |
Just check if ms_timer < last_print_time and if so add 2^16 no?
Edit: You also need to up to an uint32 for this if you can. |
You can use the Word COM object to open the work document and then you manipulate it. Make sure to add a reference for Microsoft Word first.
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop.Word
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub... |
Accessing Firefox cache from an XPCOM component |
|c++|firefox|gecko|xpcom| |
Does anybody know how to get local path of file cached by Firefox based on its URL from an XPCOM component? |
Keep these goals in mind (adapted from xUnit test patterns)
- Tests should reduce risk, not
introduce it.
- Tests should be easy to run.
- Tests should be easy to maintain as
the system evolves around them
Some things to make this easier:
- Tests should only fail because of
one reason.... |
PowerShell has a Write-Progress cmdlet that creates an in-console progress bar that you can update and modify as your script runs. |
[Project Gazelle][1] (an open source torrent site) provides a step by step guide on setting up Memcached on the site which you can easily use on any other website you might want to set up which will handle a lot of traffic.
Grab down the source and read the documentation.
[1]: http://projectgazelle.org/ |
There are performance benefits, but here is one that has not been mentioned: row migration. With char, you reserve the entire space in advance.So let's says you have a varchar2(1000), and you store 10 characters, you will use up all 1000 charaters of space. In a varchar2, you will only use 10 characters. The problem co... |
#!/bin/sh
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
PRG=`readlink "$PRG"`
done
scriptdir=`dirname "$PRG"` |
You can use `copy /b` like this:
copy /b file1+file2 destfile |
Is there raplacement to cat on Windows |
|command-line|windows|scripting| |
I need to join to binary files is *.bat script on Windows. How can I achieve that? |
Is there replacement for cat on Windows |
|windows|command-line|scripting| |
I need to join to binary files in *.bat script on Windows. How can I achieve that? |
Just use the dos copy command with multiple source files and one destination file.
copy file1+file2 appendedfile
You might need the /B option for binary files |
I wish there was some way to accept multiple answers. Based on everyone's recommendations, I think I will stick with the multiple parameters, changing the strings to enums/constants, and moving the value to be converted to the first position in the parameter list. Inside the function, I'll use Kelvin as a common middle... |
I like to start refactoring when I need to, rather than the first opportunity that I get. You might say this is somewhat of an agile approach to refactoring. When do I feel I need to? Usually when I feel that the ugly parts of my codes are starting to spread. I think ugliness is okay as long as they are contained, but ... |
Hmm, I see that [Process Explorer][1] can do it, although its graphs are not too convenient. Still looking for alternative / better ways to do it.
[1]: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx |
Perfmon.exe is built into windows. |
DECLARE @binvalue binary(4)
SET @binvalue = 0x61000000
PRINT @binvalue
PRINT cast('a' AS binary(4))
PRINT cast(0x61 AS varchar)
Do not cast.
Casting converts the binary to text by value on the corresponding collation setting for the specific database. |
DECLARE @binvalue binary(4)
SET @binvalue = 0x61000000
PRINT @binvalue
PRINT cast('a' AS binary(4))
PRINT cast(0x61 AS varchar)
Do not cast.
Casting converts the binary to text by value on the corresponding collation setting for the specific database.
[Begin Edit]
If you need the pri... |
I tried foldershare and did all the setup and it's not syncing. Also when I chose On Demand type of synchronization instead of Automatic, I expected to see an option to trigger the synchronization manually and I couldn't find it. I didn't like the software.
Looked around and found syncplicity and it works fine. |
For SaaS applications, you use multiple databases for multiple tenants, but usually don't split it module-wise.
This is the most common model I have seen in SaaS application design. Your base schema is replicated for each tenant that you add to your application. |
If you can get your hands on the hardware, or work with someone who can, you can turn off the cache. Some CPUs have a pin that, if wired to ground instead of power (or maybe the other way), will disable all internal caches. That will give predictability but not speed!
Failing that, maybe in certain places in the s... |
[Process Explorer][1] can show total CPU time taken by a process, as well as a history graph per process.
[1]: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx |
The general idea of loader lock:
The system runs the code in DllMain inside a lock (as in - synchronization lock). Therefore, running non-trivial code inside DllMain is "asking for a deadlock", as described [here][1].
The question is, why are you trying to run code inside DllMain? Is it crucial that this code run i... |
How do I access performance counters from C# in Windows XP Embedded? |
|c#|.net|windows-xp-embedded| |