instruction stringlengths 0 30k ⌀ |
|---|
It is super simple and slim. You could do it with browser via http verb: GET.
I haven't find a browser can manually do generic http POST request easily |
To connect/perform operations on an SQL server db:
using System.Data;
using System.Data.SqlClient;
string connString = "Data Source=...";
SqlConnection conn = new SqlConnection(connString); // you can also use ConnectionStringBuilder
connection.Open();
string sql = "..."; // your SQL... |
The only problem I have with them is that they don't go far enough. The same release of the compiler that added automatic properties, added partial methods. Why they didnt put the two together is beyond me. A simple "partial On<PropertyName>Changed" would have made these things really really useful. |
Ditto on what Justin said, but you should do this instead:
Integer.toString(myInt);
It saves an allocation or two and is more readable. |
This isn't C# per se, but I haven't seen anyone who really uses `System.IO.Path.Combine()` to the extent that they should. In fact, the whole Path class is really useful, but **no one uses it!**
I'm willing to bet that every production app has the following code, even though it shouldn't:
string path = dir + ... |
There is a way you can programmatically provision your devices. If you're using managed code, you can use Microsoft.WindowsMobile.Configuration.dll to do most of the work for you. If you're using unmanaged code, you have to use DMProcessConfigXML native function.
There's more details in [this blog post by Andrew Arn... |
If you only need some simple process orchestration, Spring's own [Web Flow][1], despite its name can serve as a orchestration task manager. If you need to preserve state for several days then you will need to become an 'early adopter' of one of the open-source projects. You may want to look at [Eclipse's BPEL projec... |
There's also [parallel-junit][1]. Depending on how you currently execute your tests its convenience may vary - the idea is just to multithread on a single system that has multiple cores. I've played with it briefly, but it's a change from how we currently run our tests.
[Hudson][2], the continuous integration engin... |
You need to pass a [function pointer][1]. The syntax is a little cumbersome, but it's really powerful once you get familiar with it.
[1]: http://www.newty.de/fpt/fpt.html#passPtr |
ASP.Net Datagrid: in Footer calculate Avg or Sum for column |
|asp.net|vb.net|datagrid| |
I have a datagrid getting bound to a dataset, and I want to display the average result in the footer for a column populated with integers.
The way I figure, there's 2 ways I can think of:
1."Use the **Source**, Luke"
In the code where I'm calling DataGrid.DataBind(), use the DataTable.Compute() method (*or in ... |
I started with the [C# Station][1] tutorials. "Getting started with Visual C#" gives me the creeps...
[1]: http://www.csharp-station.com/Tutorial.aspx |
Give this a try:
select *
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where CONSTRAINT_TYPE = 'Primary Key' and Table_Name = 'whatever'
|
Do you want the server name? Or the host name?
[Request.Url.Host](http://stackoverflow.com/questions/96029/get-url-of-aspnet-page-in-code-behind#96052) ala Stephen
[Dns.GetHostName](http://msdn.microsoft.com/en-us/library/system.net.dns.gethostname.aspx) - Server name
[Request.Url](http://msdn.microsoft.com/en... |
Unfortunately, C# arrays aren't guaranteed to be in contiguous memory like they are in closer-to-the-metal languages like C. So, no. There's no way to convert double[,,] to double[] without an element-by-element copy. |
Simplfying @KTC's, since we have the size of the array in the template argument:
template<typename T, int SIZE>
int arraySize(const T(&arr)[SIZE])
{
return SIZE;
}
Disadvantage is you will have a copy of this in your binary for every Typename, Size combination. |
@hash{@array} = (1) x @array; |
I don't believe the way C# stores that data in memory would make it feasible the same way a simple cast in C would. Why not use a 1d array to begin with and perhaps make a class for the type so you can access it in your program as if it were a 3d array?
|
A delegate does share a lot in common with a interface reference that has a single method from the caller's point of view.
In the first example, Baz and Bar are classes, which can be inherited and instantiated. In the second example, Baz and Bar are methods.
You can't apply interface references to just any class... |
1. Make sure you have your indexes set up appropriately. Indexing on id, revision would be good.
2. Here's a different take on your query. Haven't checked its execution plan, but if you set up the index well it should help:
select c.* from comments c<br>
inner join (select id,max(revision) as maxrev from comme... |
1. Make sure you have your indexes set up appropriately. Indexing on id, revision would be good.
2. Here's a different take on your query. Haven't checked its execution plan, but if you set up the index well it should help:
select c.* from comments c<br>
inner join (select id,max(revision) as maxrev from comme... |
string multiple commands together using the **&&** command:
**./run.sh && tail -f log.txt**
or
**kill -9 1111 && ./start.sh** |
How to default the source folder for new JUnit tests in Eclipse? |
|java|eclipse|usability|junit| |
Most of our Eclipse projects have multiple source folders, for example:
- src/main/java
- src/test/java
When you right-click on a class and choose New JUnit Test, the default source folder for the new test is "src/main/java" (presumably the first source folder listed in the project properties).
Is there a... |
Check the options of your editor or find an editor/IDE that allows you to convert TABs to spaces. I usually set the options of my editor to substitute the TAB character with 4 spaces, and I never run into any problems. |
Start at the [Windows Mobile Developer Center][1]. There you will find a great getting start section with lots of links to the software you need and tutorials. Windows Mobile development is a lot of fun. :)
[1]: http://msdn.microsoft.com/en-us/windowsmobile/default.aspx |
Long commands split over multiple lines in Vista/DOS batch (.bat) file |
|command-line|batch|batch-file|dos| |
How do I make long commands go over multiple lines in a Vista/DOS batch file?
|
If you are interested in seeing a tree like structure for your directories, sources, methods etc try using emacs code browser http://ecb.sourceforge.net/.
|
If your XML Serialization generated assembly is not in the same Load context as the code attempting to use it, you will run into awesome errors like:
System.InvalidOperationException: There was an error generating the XML document.
---System.InvalidCastException: Unable to cast object
of type 'MyNamesp... |
Check out the [Stylesheets][1] facility in Qt 4. While it's still a hassle, it's way easier than doing a full-on custom style. You can just adjust one visual facet at a time and try it out.
It pays attention to inheritance. So if you style the font in QWidget, then every visual widget will also use that font. An... |
The collations are not always favorable. You'll get umlats collating to non umlatted versions which is not always correct. Might want to go w/ utf8_bin, but then everything is case sensitive as well. |
Courtesy of Judith Bishop, [http://patterns.cs.up.ac.za/][1]
This singleton pattern implementation ensures lazy initialisation.
// Singleton PatternJudith Bishop Nov 2007
// Generic version
public class Singleton<T> where T : class, new()
{
Singleton() { }
class ... |
Get Methods: One vs Many |
|oop|jakarta-ee| |
getEmployeeNameByBatchId(int batchID)<BR>
getEmployeeNameBySSN(Object SSN)<BR>
getEmployeeNameByEmailId(String emailID)<BR>
getEmployeeNameBySalaryAccount(SalaryAccount salaryAccount)<BR>
or
getEmployeeName(int typeOfIdentifier, byte[] identifier) -> In this methods the typeOfIdentifier tells if identifier is ... |
|java|oop|jakarta-ee| |
I'm primarily an ASP.Net developer, but I find MVC is a better way of creating functionally complex websites (typically Line-of-Business type sites) since it allows for better separation of business logic and rules from the markup used to display data to the end-user.
For quick and dirty sites (typically with a direct... |
C# String ASCII representation |
|c#|regex|ascii|string| |
How can I insert ASCII special characters (e.g. with the ASCII value 0x01) into a string?
I ask because I am using the following:
str.Replace( "<TAG1>", Convert.ToChar(0x01).ToString() );
and I feel that there must be a better way than this. Any Ideas?
Update:
Also If I use this methodology, do I nee... |
The big difference is that AddRange mutates that list against which it is called whereas Concat creates a new List. Hence they have different uses.
Also Concat is an extension method that applies to any IEnumerable<T> and returns an IEnumerable<T> you need a .ToList() to result in a new List.
If you want to ext... |
I believe you can use `\uXXXX` to insert specified codes into your string.
ETA: I just tested it and it works. :-)
using System;
class Uxxxx {
public static void Main() {
Console.WriteLine("\u20AC");
}
}
|
Is there a way to implement a sealed class from an interface... and mock the interface instead?
Something in me feels that having sealed classes is wrong in the first place, but that's just me :) |
I was taught by learning how to solve problems in a language agnostic way using flowcharts and [PDL][1] (Program Design Language). After a couple weeks of that, I learned to convert the PDL I had written to a language. I am glad I learned that way because I have spent the majority of my years programming, solving pro... |
They each break when dropped from the same height, or are they different?
If they're the same, I go to the 50th floor and drop the first marble. If it doesn't break, I go to the 75th floor and do the same, as long as it keeps not breaking I keep going up by 50% of what's left. When it does break, I go back to one ... |
Ruby unfortunately is a bit different.
PS: My memory is a bit hazy on this so apologies if I'm wrong
instead of break/continue, it has break/next, which behave the same in terms of loops
Loops (like everything else) are expressions, and "return" the last thing that they did. Most of the time, getting the return... |
Ï've just tried using
if( typeof(T).Equals(typeof(IMyInterface) )
...
And also works, but your answer seems more robust and was what I was looking for. Thanks! |
Thanks--good answers.
This is, in fact, a DateTime type; I had to typecast "stoptime" as:
var query = from p in dbTransSummary.Transaction_Logs
where ( (DateTime) p.StopTime).Year == dtRollUpDate.Year
select |
Thanks--good answers.
This is, in fact, a DateTime type; I had to typecast "stoptime" as:
var query = from p in dbTransSummary.Transaction_Logs
where ( (DateTime) p.StopTime).Year == dtRollUpDate.Year
select
Minor point. It works great! |
As a workaround you could make a class which maintains the array in one dimensional form (maybe even in closer to bare metal form so you can pass it easily to the COM library?) and then overload operator[] on this class to make it usable as a multidimensional array in your C# code. |
Private Function IsAlpha(ByVal vChar As String) As Boolean
Const letters$ = "abcdefghijklmnopqrstuvwxyz"
If InStr(1, letters, LCase$(vChar)) > 0 Then IsAlpha = True
End Function
|
have you checked [RSE][1] (**R**emote **S**ystem **E**xplorer) ? I think it's pretty close to what you want to achieve
[1]: http://wiki.eclipse.org/TM_and_RSE_FAQ#What_is_the_Target_Management_Project.3F |
have you checked [RSE][1] (**R**emote **S**ystem **E**xplorer) ? I think it's pretty close to what you want to achieve.
[a blog post about it, with screenshots][2]
[1]: http://wiki.eclipse.org/TM_and_RSE_FAQ#What_is_the_Target_Management_Project.3F
[2]: http://ikool.wordpress.com/2008/07/22/ssh-access-t... |
Open a file with su/sudo inside Emacs |
|emacs|sudo|file-permissions| |
Suppose I want to open a file in an existing Emacs session using `su` or `sudo`, without dropping down to a shell and doing `sudoedit` or `sudo emacs`. One way to do this is
(require 'tramp)
C-c C-f /sudo::/path/to/file
but this requires an expensive [round-trip through SSH][1]. Is there a more direct wa... |
|emacs|file-permissions|sudo| |
Suppose I want to open a file in an existing Emacs session using `su` or `sudo`, without dropping down to a shell and doing `sudoedit` or `sudo emacs`. One way to do this is
(require 'tramp)
C-c C-f /sudo::/path/to/file
but this requires an expensive [round-trip through SSH][1]. Is there a more direct wa... |
Can the ffmpeg av libs return an accurate PTS? |
|asp.net|vb.net|report|datagrid| |
I have a datagrid getting bound to a dataset, and I want to display the average result in the footer for a column populated with integers.
The way I figure, there's 2 ways I can think of:
1."Use the **Source**, Luke"
In the code where I'm calling DataGrid.DataBind(), use the DataTable.Compute() method (*or in ... |
**Declaration**
A prototype for a function which takes a function parameter looks like the following:
void func ( void (*f)(int) );
This states that the parameter f will be a pointer to a function which has a void return type and which takes a single int parameter. The following function (print) is an exam... |
I personally feel that you'd have to recompile the application using a 64-bit compiler (obviously on a 64-bit machine) to get the most of Memcached on a 64-bit platform. This may not be an easy task depending on the code. If it was written with 64-bit portability in mind then it could be a simple recompile. If it hasn'... |
If you're going to use a flat file to persist data why not use XML to structure the data?
PHP has a built-in XML parser: http://uk.php.net/xml |
Remember that most computers these days ship with CPU ID disabled in the BIOS. See [CPUID on Wikipedia][1]
[1]: http://en.wikipedia.org/wiki/CPUID "CPUID [Wikipedia]" |
If what you are looking for is an easy to follow tutorial, then you should head over to the www.ASP.net website.
Here is a link to the starter video page: [http://www.asp.net/learn/videos/video-49.aspx][1]
Here is the video if you want to download it: [video download][2]
and here is a link to the C# project ... |
cdecl offers a command line interface so let's give it a try:
cdecl> explain int ***c[][]
declare c as array of array of pointer to pointer to pointer to int
another example
explain int (*IMP)(ID,SEL)
declare IMP as pointer to function (ID, SEL) returning int
However there is a whole cha... |
I think it boils down to the design of your objects. Because lazy-loading can be enforced in the per-object level, you can take advantage of that fact when you think about session management.
For example, I have a bunch of objects which are data-rich and lazy loaded, and I have a grid/summary view, and a details vie... |
long to HWND (VS8 C++) |
|casting|long-integer|hwnd| |
How can I cast long to HWND (C++ visual studio 8)?
Thanks. |
How can I cast long to HWND (C++ visual studio 8)?
Long lWindowHandler;
HWND oHwnd = (HWND)lWindowHandler;
But I got the following warning:
> warning C4312: 'type cast' : conversion from 'LONG' to 'HWND' of greater size
Thanks. |
Daniel mentioned <http://cocoadev.com>.
More specifically, check out <http://www.cocoadev.com/index.pl?ObjectLibrary>.
"This page is for tracking re-usable Cocoa classes that can be mixed, matched, and dropped fairly easily into existing Cocoa projects to add useful functionality." |
I only use mysql_real_escape_string before inserting variables into an SQL statement. You'll just get yourself confused if some of your variables are *already* escaped, and then you escape them again. It's a classic bug you see in newbies' blog webapps:
> When someone writes an apostrophe it keeps on adding slashes ... |
Reading a PNG image file in .Net 2.0 |
|c#|.net| |
I'm using C# in .Net 2.0, and I want to read in a PNG image file and check for the first row and first column that has non-transparent pixels.
What assembly and/or class should I use? |
Try adding a datetime.datetime to a datetime.timedelta. If you only want the time portion, you can call the time() method on the resultant datetime.datetime object to get it. |
Assuming you're using .Net I think you'll need to create your own control (or buy one).
|
If you index to code with Doxygen you can see from where is each function referenced. However, you would have to browse through each class (1 HTML page per class) and scan for those that don't have anything pointing to them.
Alternatively, you could use ctags to generate list of all functions in the code, and then u... |
Consider packaging it up as a plugin for one of the major Javascript libraries such as [jQuery][1] - see http://docs.jquery.com/Plugins/Authoring for more details. This way it can be included on their [plugin page][2] which will get it good exposure as they have a huge developer base and it'll be one of their first por... |
If you have some guess of the preferred size of the pool you can create fixed size pool using stack structure using array (the fastest possible solution). Then you need to implement four phases of object life time hard initialization (and memory allocation), soft initialization, soft cleanup and hard cleanup (and memor... |
I'm personally not very big a fan of such puzzle questions, I prefer actual programming exercises in interviews.
That said, first it would depend on if I can tell if they are broken or not from the floor I am dropping them at. I will presume I can.
I would go up to the second floor, drop the first marble. If it... |
The reason is that a generic class like `List<>` is, for most purposes, treated externally as a normal class. e.g. when you say `List<string>()` the compiler says `ListString()` (which contains strings). [Technical folk: this is an extremely plain-English-ified version of what's going on]
Consequently, obviously the... |
Two marbles |
|interview-questions|puzzle| |
One of those classic programming interview questions...
You are given two marbles, and told that they will break when dropped from some certain height (and presumably suffer no damage if dropped from below that height). You’re then taken to a 100 story building (presumably higher than the certain height), and asked ... |
One of those classic programming interview questions...
You are given two marbles, and told that they will break when dropped from some certain height (and presumably suffer no damage if dropped from below that height). You’re then taken to a 100 story building (presumably higher than the certain height), and asked ... |
One of those classic programming interview questions...
You are given two marbles, and told that they will break when dropped from some certain height (and presumably suffer no damage if dropped from below that height). You’re then taken to a 100 story building (presumably higher than the certain height), and asked ... |
|ffmpeg|dts|mpeg|pts| |
I'm working with an mpeg stream that uses a IBBP... GOP sequence. The (DTS,PTS) values returned for the first 4 AVPackets are as follows: I=(0,3) B=(1,1) B=(2,2) P=(3,6)
The PTS on the I frame looks like it is legit, but then the PTS on the B frames cannot be right, since the B frames shouldn't be displayed before t... |
How to insert multiple records and get the identity value? |
|sql-server|sql| |
I'm inserting multiple records into a table A from another table B. Is there a way to get the identity value of table A record and update table b record with out doing a cursor?
Create Table A
(id int identity,
Fname nvarchar(50),
Lname nvarchar(50))
Create Table B
(Fname nvarchar(50),
Lname nvarchar(50),
N... |
|sql|sql-server| |
I'm inserting multiple records into a table A from another table B. Is there a way to get the identity value of table A record and update table b record with out doing a cursor?
Create Table A
(id int identity,
Fname nvarchar(50),
Lname nvarchar(50))
Create Table B
(Fname nvarchar(50),
Lname nvarchar(50),
N... |