instruction stringlengths 0 30k ⌀ |
|---|
In the designer, set the form's Visible property to false. Then avoid calling Show() until you need it.
A better paradigm is to not create an instance of the form until you need it. |
One trick I like it to use the splat(*) expander on objects other than Arrays. Here's an example on a regular expression match:
match, text, number = *"Something 981".match(/([A-z]*) ([0-9]*)/)
Other examples include:
a, b, c = *('A'..'Z')
Job = Struct.new(:name, :occupation)
tom = Job... |
An interesting idea. Note that you don't actually need to write a browser-specific plugin to do this. Some [people have experimented][1] with using JRuby in an Applet to execute code embedded within `<script type="text/ruby">`. Such a solution may be slower on startup (due to the overhead of loading an entire JVM in... |
For Linux:
Try [Google Perftools](http://code.google.com/p/google-perftools/)
There are a lot of tools that do similar alloc/free counting, the pros of Goolge Perftools:
* Quite fast (in comparison to valgrind: very fast)
* Comes with nice graphical display of results
* Has other useful capabilities: c... |
I would recommend [wxPython][1]
[1]: http://www.wxpython.org/ |
I would recommend [wxPython][1]
It's beautifully cross platform and you can get per pixel control and if you change your mind about that you can use it with libraries such as pyglet or agg.
You can find some useful examples for just what you are trying to do in the docs and demos download.
[1]: http://www.wx... |
Try setting Buffer="True" in the Page Directive of the page and not in codebehind. |
Try setting Buffer="True" in the Page Directive of the page and not in codebehind.
Edit: I just tried this in VS2008 on a Web Site project:
1. Create new item
2. Choose "Web page"
3. Leave all the html-tags in there, just for fun
4. Fill the page_load like this
protected void Page_Load(objec... |
use stored procedures with LINQ...but don't let the sprocs turn into a data access layer! |
Ruby, albeit not that short:
class Overflow
def initialize
Overflow.new
end
end
Overflow.new
|
With Core Data, you should have a separate managed object context to use for your import thread, connected to the same coordinator and persistent store. You cannot simply throw objects created in a context used by the main thread into another thread and expect them to work. Furthermore, you cannot do your own locking... |
I recommend [Subversion][1]. Setting up a repository and using it is actually fairly trivial, even from the command line. Here's how it would go:
# if you haven't setup your repo (repository)
###**1)** Make sure you've got Subversion installed on your server
<pre><code>$ which svn
/usr/bin/svn
</code></pre>
... |
How do you execute a dynamically loaded JavaScript block? |
|javascript|ajax| |
I'm working on a web page where I'm making an AJAX call that returns a chunk of HTML like:
<div>
<!-- some html -->
<script type="text/javascript">
/** some javascript */
</script>
</div>
I'm inserting the whole thing into the DOM, but the JavaScript isn't being run. Is th... |
I think a utility method could help make this cleaner.
public static class Convert
{
public static T? To<T>(string value, Converter<string, T> converter) where T: struct
{
return string.IsNullOrEmpty(value) ? null : (T?)converter(value);
}
}
then
Employ... |
ericmayo.myopenid.com is so wrong, that someone with enough reputation should downvote him.
The C or C++ runtime libraries are managing the heap which is given to it in blocks by the Operating System, somewhat like you indicate, Eric. But it *is* the responsibility of the developer to indicate to the compiler which... |
Thread safe in Java 5+:
class Foo {
private volatile Bar bar = null;
public Bar getBar() {
if (bar == null) {
synchronized(this) {
if (bar == null)
bar = new Bar();
}
}
retu... |
Thread safe in Java 5+:
class Foo {
private volatile Bar bar = null;
public Bar getBar() {
if (bar == null) {
synchronized(this) {
if (bar == null)
bar = new Bar();
}
}
retu... |
Thread safe in Java 5+:
class Foo {
private static volatile Bar bar = null;
public static Bar getBar() {
if (bar == null) {
synchronized(this) {
if (bar == null)
bar = new Bar();
}
}
... |
NHibernate.MappingException: No persister for: |
|nhibernate|c#|.net| |
Now, before you say it I DID google and my hbm.xml file IS an Embedded Resource.
Here is the code I am calling:
ISession session = GetCurrentSession();
var returnObject = session.Get<T>(Id);
Here is my mapping file for the class:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns... |
|c#|.net|nhibernate| |
Now, before you say it I DID google and my hbm.xml file IS an Embedded Resource.
Here is the code I am calling:
ISession session = GetCurrentSession();
var returnObject = session.Get<T>(Id);
Here is my mapping file for the class:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-m... |
Very slow compile times on Visual Studio |
|visual-studio|suggestions|compilation| |
We are getting very slow compile times, which can take upwards of 20+ minutes on dual core 2GHz, 2G Ram machines.
A lot of this is due to the size of our solution which has grown to 70+ projects, as well as VSS which is a bottle neck in itself when you have a lot of files. (swapping out VSS is not an option unfort... |
No "VALUES", no parenthesis:
INSERT INTO Table2(LongIntColumn2, CurrencyColumn2)
SELECT LongIntColumn1, Avg(CurrencyColumn) as CurrencyColumn1 FROM Table1 GROUP BY LongIntColumn1; |
Say you're doing this on /dev/tty1.
**in the shell**
chown *youruser* /dev/tty1
**then in a Perl script called example.pl**
open PORT, "</dev/tty1" || die "Can't open port: $!";
while (defined ($_ = <PORT>))
{
do_something($_);
}
close PORT;
Obviously there is more to do... |
For a VB or C# app, one way to do this is by using Office Interop. This depends on which version of Excel you're working with.
For Excel 2003, this MSDN article is a good place to start.
[Understanding the Excel Object Model from a Visual Studio 2005 Developer's Perspective ][1]
You'll basically need to do the ... |
Here is the process to clarify this:
1. user doubleclicks row
2. app fetches data from db, processes fetched data and fills controls on the same form as the DataGridView
3. user interacts with controls and finally presses apply button on the same form
4. app processes state of controls, writes data to db and ... |
Windows Mobile 6 devices come with .NET Compact Framework 2.0 in ROM and also expose .NET APIs for a lot of things (camera, system notifications, email, contacts, ...).
I'd recommend using Visual Studio 2008 and the [refresh version of the Windows Mobile 6 SDK][1], which includes emulators, documentation, tools and ... |
Remove both VALUES and the parenthesis.
INSERT INTO Table2 (LongIntColumn2, CurrencyColumn2)
SELECT LongIntColumn1, Avg(CurrencyColumn) FROM Table1 GROUP BY LongIntColumn1 |
Note the caveat in the manual at <http://uk.php.net/error_reporting>:
>> Most of E\_STRICT errors are evaluated at the compile time thus such errors are not reported in the file where error_reporting is enhanced to include E\_STRICT errors (and vice versa).
If your underlying system is configured to report E\_STR... |
Note the caveat in the manual at <http://uk.php.net/error_reporting>:
>> Most of E\_STRICT errors are evaluated at the compile time thus such errors are not reported in the file where error_reporting is enhanced to include E\_STRICT errors (and vice versa).
If your underlying system is configured to report E\_STR... |
If you want to do something like this for interthread or interprocess communication, then you need to have more than just an atomic read/write guarantee. In your example, it appears that you want the values written to indicate that some work is in progress and/or has been completed. You will need to do several things,... |
Calling base.Dispose() automatically from derived classes |
|c#|reflection|idisposable| |
## Background ##
We are developing a system in C# 3.0 with a relatively big class hierarchy. Some of these classes, anywhere in the hierarchy, have resources that need to be
disposed of, those implement the **IDisposable** interface.
## The Problem ##
Now, to facilitate maintenance and refactoring of the cod... |
## Edit - New Question ##
Ok lets rephrase the question more generically.
Using reflection, is there a way to dynamically call at runtime a base class method that you may be overriding. You cannot use the 'base' keyword at compile time because you cannot be sure it exists. At runtime I want to list my ancestors ... |
This client, is it a desktop application and not some software that runs inside the browser? In that case, please just supply a regular download installer application. My personal experience with browser-hosted installers is that they are just confusing and the few I have seen seemed to be poorly coded in some way.
... |
Try setting Buffer="True" in the Page Directive of the page and not in codebehind.
Edit: I just tried this in VS2008 on a Web Site project:
1. Create new item
2. Choose "Web page"
3. Leave all the html-tags in there, just for fun
4. Fill the page_load like this
protected void Page_Load(objec... |
Factory classes are more heavyweight, but give you certain advantages. In cases when you need to build your objects from multiple, raw data sources they allow you to encapsulate only the building logic (and maybe the aggregation of the data) in one place. There it can be tested in abstract without being concerned with ... |
An alternative would be add the public half of the user's key to the authorized-keys file on the target system. On the system you are initiating the transfer from, you can run an <tt>ssh-agent</tt> daemon and add the private half of the key to the agent. The batch job can then be configured to use the agent to get the ... |
General Coding Guideline:
* Resources should be deallocated at the same "layer" (function/class/library) where they are allocated.
* If this is not possible, try to use some automatic deallocation (boost shared pointer...) |
I am using #3: the boost string format library - but I have to admit that I've never had any problem with the differences in format specifications.
Works like a charm for me - and the external dependencies could be worse (a very stable library) |
I am using #3: the boost string format library - but I have to admit that I've never had any problem with the differences in format specifications.
Works like a charm for me - and the external dependencies could be worse (a very stable library)
Edited: adding an example how to use boost::format instead of printf:... |
I am using #3: the boost string format library - but I have to admit that I've never had any problem with the differences in format specifications.
Works like a charm for me - and the external dependencies could be worse (a very stable library)
Edited: adding an example how to use boost::format instead of printf:... |
Thread safe in Java 5+:
class Foo {
private static volatile Bar bar = null;
public static Bar getBar() {
if (bar == null) {
synchronized(Foo.class) {
if (bar == null)
bar = new Bar();
}
... |
Short solution in K&R C, could be compiled:
main(){main()}
14 bytes
|
I find Hackbar to be quite useful. Very useful if you want to edit the querystring part of the url, to test for vulnerabilities, or just general other types of testing where you might end up with complicated query string values. |
MyISAM's supposed speed benefits can actually go away pretty quickly - the fact that it lacks row-level locking means small updates can cause large amounts of data to be locked, and queries to block. Because of that, I'm skeptical of claimed MyISAM speed benefits: start doing several UPDATEs, and the queries per secon... |
How to stop CAS security assertions from a FullTrust assembly |
|.net|cas|full-trust| |
I have a FullTrust assembly, Assembly A, which calls a 3rd party component, Assembly B. Is there any way I can, via A.dll.config or in A's code, prevent any CAS assertions from propagating up the stack to Assembly B, which does not have FullTrust?
I do not want to alter the machine's security policy, if possible.
|
How to stop CAS security demands from a FullTrust assembly |
I have a FullTrust assembly, Assembly A, which calls a 3rd party component, Assembly B. Is there any way I can, via A.dll.config or in A's code, prevent any CAS demands from propagating up the stack to Assembly B, which does not have FullTrust?
I do not want to alter the machine's security policy, if possible.
|
This shall help you in a way: [Windows Driver Kit][1]
[1]: http://www.microsoft.com/whdc/devtools/wdk/default.mspx |
Point #1 is a premature memory optimization. #2 is a premature performance optimization. Have you profiled your app to determine if memory or CPU bottlenecks are causing problems for you? If not, why sacrifice a more maintainable design for an "optimization" that doesn't help your users?
I would strongly recommend y... |
If the data doesn't need to be completely up to date, you might also like to think about using a data warehousing tool for OLAP purposes (such as [MSOLAP][1]). The can perform lightning fast read-only queries based on pre-calculated data.
[1]: http://www.mosha.com/msolap/ |
What's a good resource for starting to write a programming language, that's not context free? |
|python|languages|compiler-construction|interpreters| |
I'm looking to write a programming language for fun, however most of the resource I have seen are for writing a context free language, however I wish to write a language that, like python, uses indentation, which to my understanding means it can't be context free. |
I can not think of a scenario where NetworkStream.Write wouldn't send the data to the server as soon as possible. Barring massive network congestion or disconnection, it should end up on the other end within a reasonable time. Is it possible that you have a protocol issue? For instance, with HTTP the request headers... |
I can not think of a scenario where NetworkStream.Write wouldn't send the data to the server as soon as possible. Barring massive network congestion or disconnection, it should end up on the other end within a reasonable time. Is it possible that you have a protocol issue? For instance, with HTTP the request headers... |
You need to get the full stack trace of the RuntimeException and its causes.
Please edit your answer to add that information. |
I'm not able to get an error when implicitly casting char** to const char * const *, at least on MSVC 14 (VS2k5) and g++ 3.3.3. GCC 3.3.3 issues a warning, which I'm not exactly sure if it is correct in doing.
test.c:
#include <stdlib.h>
#include <stdio.h>
void foo(const char * const * bar)
{
... |
Its far better to do this right than put it off any longer. Vista is Microsoft's way of saying they aren't letting people get away with ignoring security issues any more and encouraging people to update their code.
I'm sure other users here will be able to point you are some MSDN best practices about writing ActiveX... |
Xtreme Toolkit Pro controls
http://www.codejock.com/products/toolkitpro/ |
At my company, we tend to store all database items in source control as individual scripts just as you would for individual code files. Any updates are first made in the database and then migrated into the source code repository so a history of changes is maintained.
As a second step, all database changes are migr... |
How Many Network Connections Can a Computer Support? |
|networking|network-programming| |
When writing a custom server, what are the best practices or techniques to determine maximum number of users that can connect to the server at any given time? I would assume that the capabilities of the computer hardware, network capacity, and server protocol would all be important factors. Also, would you consider i... |
I find the following implementations just hilarious:
[The Evolution of a Haskell Programmer]( http://www.willamette.edu/~fruehr/haskell/evolution.html)
[Evolution of a Python programmer](http://dis.4chan.org/read/prog/1180084983/)
Enjoy! |
For starters, the best way is to read a lot of code. Since Linux is Open Source, you'll find dozens of drivers. Find one that works in some ways like what you want to write. You'll find some decent and relatively easy-to-understand code (the loopback device, ROM fs, etc.)
You can also use the lxr.linux.no, which is ... |
When I worked on commercial flight software, we used CMM and as our processes improved our ability to accurately predict completion times improved. But this was a cumbersome process, other approaches should work just as well. |
CMM doesn't really speak to the quality of the software, but more towards the documentation and repeatability of the process. In other words, it is possible to have an orderly and repeatable development process, but still create crappy software. As long as the process is properly documented, it is possible to achieve C... |
"C-x d" accesses the directory editor. "C-x C-f" will do it as well if you give it a directory instead of a file.
There's also IBuffer mode, which lets you deal with your open buffers in a very similar fashion to Dired: [http://www.emacswiki.org/cgi-bin/wiki/IbufferMode](http://www.emacswiki.org/cgi-bin/wiki/Ibuffer... |
The value of a will be b, but the value of the _statement_ will be c. That is, in
d = (a = b, c);
a would be equal to b, and d would be equal to c
|
Not in versions below SQL 2008. In SQL Server 2008 there's the resource governor. Using that you can assign logins to groups based on properties of the login (login name, application name, etc). The groups can then be assigned to resource pools and limitations or restrictions i.t.o. resources can be applied to those re... |
Try this:
var input = 'foo bar "lorem ipsum" baz';
var R = /(\w|\s)*\w(?=")|\w+/g;
var output = input.match(R);
output is ["foo", "bar", "lorem ipsum", "baz"]
Note there are no extra double quotes around lorem ipsum
It won't handle escaped double quotes though (is that a problem?):
... |
char[] to hex string exercise |
|c++|optimization|hex| |
Below is my current char* to hex string function. I wrote it as an exercise in bit manipulation. It takes ~5ms on a AMD Athlon MP 2800+ to hexify a 10 million byte array. Is there any trick or other way that I am missing?
How can I make this faster?
static const char _hex2asciiU_value[16] =
{ '0',... |
|c++|hex|optimization| |
Below is my current char* to hex string function. I wrote it as an exercise in bit manipulation. It takes ~5ms on a AMD Athlon MP 2800+ to hexify a 10 million byte array. Is there any trick or other way that I am missing?
How can I make this faster?
Compiled with -O3 in g++
static const char _hex2asciiU_... |
|c++|optimization|hex| |
Below is my current char* to hex string function. I wrote it as an exercise in bit manipulation. It takes ~7ms on a AMD Athlon MP 2800+ to hexify a 10 million byte array. Is there any trick or other way that I am missing?
How can I make this faster?
Compiled with -O3 in g++
static const char _hex2asciiU_... |
We are getting very slow compile times, which can take upwards of 20+ minutes on dual core 2GHz, 2G Ram machines.
A lot of this is due to the size of our solution which has grown to 70+ projects, as well as VSS which is a bottle neck in itself when you have a lot of files. (swapping out VSS is not an option unfort... |
|c#|visual-studio|suggestions|compilation| |
We are getting very slow compile times, which can take upwards of 20+ minutes on dual core 2GHz, 2G Ram machines.
A lot of this is due to the size of our solution which has grown to 70+ projects, as well as VSS which is a bottle neck in itself when you have a lot of files. (swapping out VSS is not an option unfort... |
We are getting very slow compile times, which can take upwards of 20+ minutes on dual core 2GHz, 2G Ram machines.
A lot of this is due to the size of our solution which has grown to 70+ projects, as well as VSS which is a bottle neck in itself when you have a lot of files. (swapping out VSS is not an option unfort... |
I have two friends who originally started writing an application using Ruby on Rails, but ran into a number of issues and limitations. After about 8 weeks of working on it, they decided to investigate other alternatives.
They settled on the [Catalyst Framework][1], and Perl. That was about 4 months ago now, and th... |
In absence of general statistics, collect your own.
Check out http://fingerprintapp.com/email-client-stats for a ready-made statistics collection tool, and see http://www.mattbrindley.com/fingerprint-email-client-usage-1/ for a write-up about it. Matt Brindley also offers this gem: "*So far only Outlook has proved a... |
My solution to your problem would be to either:
1 - use int instead of enums: Declare your ints in an anonymous namespace in your CPP file (not in the header):
namespace
{
const int FUNCTIONALITY_NORMAL = 0 ;
const int FUNCTIONALITY_RESTRICTED = 1 ;
const int FUNCTIONALITY_FOR_PRO... |
without jquery:
var links = document.getElementsByTagName("a");
for(var i in links) {
var link = links[i];
console.log(link.offsetWidth, link.offsetHeight);
}
try this page for a func to get the x and y values:
[http://blogs.korzh.com/progtips/2008/05/28/absolute-coordinates-of-do... |
without jquery:
var links = document.getElementsByTagName("a");
for(var i in links) {
var link = links[i];
console.log(link.offsetWidth, link.offsetHeight);
}
try this page for a func to get the x and y values:
[http://blogs.korzh.com/progtips/2008/05/28/absolute-coordinates-of-do... |
What is a good tool to aid in browsing/following C code? |
|c|browser| |