Is there a way in sql (or tsql) to select the median of a column of numbers? I know you can sort by the column and pick the middle value, but it would be nice if there was a built-in function
What I have is a txt file that is huge, 60MB. I need to read each line and produce a file, split based on a delimiter. I'm having no issue reading the file or producing the file, my complication comes from the delimiter, it can't see the delimiter. If anybody could offer a suggestion on how to read that delimiter I would be so grateful.
delimiter = Ç
public void file1()
{
string betaFilePath = @"C:\dtable.txt";
StringBuilder sb = new StringBuilder();
using (FileStream fs = new FileStream(betaFilePath, FileMode.Open))
using (StreamReader rdr = new StreamReader(fs))
{
while (!rdr.EndOfStream)
{
string[] betaFileLine = rdr.ReadLine().Split('Ç');
{
sb.AppendLine(betaFileLine[0] + "ç" + betaFileLine[1] + betaFileLine[2] + "ç" + betaFileLine[3] + "ç" + betaFileLine[4] + "ç" + betaFileLine[5] + "ç" + betaFileLine[6] + "ç" + betaFileLine[7] + "ç" + betaFileLine[8] + "ç" + betaFileLine[9] + "ç" + betaFileLine[10] + "ç");
}
}
}
using (FileStream fs = new FileStream(@"C:\testarea\load1.txt", FileMode.Create))
using (StreamWriter writer = new StreamWriter(fs))
{
writer.Write(sb.ToString());
}
}
There's a bug in delphi 6 which you can find some reference online for when you import a tlb the order of the parameters in an event invocation is reversed. It is reversed once in the imported header and once in TServerEventDIspatch.Invoke.
you can find more information about it here:
http://cc.embarcadero.com/Item/16496
somewhat related to this issue there appears to be a memory leak in TServerEventDispatch.Invoke with a parameter of a Variant of type Var_Array (maybe others, but this is the more obvious one i could see). The invoke code copies the args into a VarArray to be passed to the event handler and then copies the VarArray back to the args after the call, relevant code pasted below:
// Set our array to appropriate length
SetLength(VarArray, ParamCount);
// Copy over data
for I := Low(VarArray) to High(VarArray) do
VarArray[I] := OleVariant(TDispParams(Params).rgvarg^[I]);
// Invoke Server proxy class
if FServer <> nil then FServer.InvokeEvent(DispID, VarArray);
// Copy data back
for I := Low(VarArray) to High(VarArray) do
OleVariant(TDispParams(Params).rgvarg^[I]) := VarArray[I];
// Clean array
SetLength(VarArray, 0);
There are some obvious work-arounds in my case: if i skip the copying back in case of a VarArray parameter it fixes the leak. to not change the functionality i thought i should copy the data in the array instead of the variant back to the params but that can get complicated since it can hold other variants and seems to me that would need to be done recursively.
Since a change in OleServer will have a ripple effect i want to make sure my change here is strictly correct.
can anyone shed some light on exactly why memory is being leaked here? I can't seem to look up the callstack any lower than TServerEventDIspatch.Invoke (why is that?)
I imagine that in the process of copying the Variant holding the VarArray back to the param list it added a reference to the array thus not allowing it to be release as normal but that's just a rough guess and i can't track down the code to back it up.
Maybe someone with a better understanding of all this could shed some light?
I have been getting into RIA services because I thought it would simplify dealing with the services layer of web applications I wish to build. I see lots of examples out there showing how to create DomainService classes which expose and consume entities that have some kind of relational database backing, and therefore have foreign-key relationships. However, I would like to know how to expose and consume normal object graphs...objects that contain references to eachother but don't have foreign keys.
For example, say I want a service operation called "GetFolderInformation(string pathToFolder)". I want this to return a custom object called "FolderInformation" structured with:
- string Name
- IEnumerable<FileInformation> Files
I cannot get this to work because it seems that RIA wants to deal with entities that have foreign key relationships. Why? Why can't the serializer just see my object references and recreate that in the proxy on the other side?
Data exists behind service layers that doesn't necessarily have foreign key relationships...like folder/file for example.
EDIT: I realized I hadn't asked my question! My question is, is there a way to do what I am trying to do?
Hi,
My "Privacy Policy" page is seen more important by Google than other really more important pages on my website.
I'm currently creating a script to generate a sitemap, should I bother with the priority?
How do you effectively assign priorities to pages? I consider one of my page important but the page have less content than another one less important to my eyes... but maybe Google bot will see it the other way around.
If my degree of "importantness" differs from the one of Google, will I get penalized on the ranking for a particular page?
Thank you for sharing your black art with us :P
Is there a way to have a recursive lambda expression in scheme without relying an external identifier?
I know you can have
(define fact (lambda (n) (if (= n 0) 1 (fact (- n 1))))
but it would be nice if fact wasn't hard coded in the lambda expression, it seems improper.
I'm trying to grasp the concept of a Batcher Sort. However, most resources I've found online focus on proof entirely or on low-level pseudocode. Before I look at proofs, I'd like to understand how Batcher Sort works. Can someone give a high level overview of how Batcher Sort works(particularly the merge) without overly verbose pseudocode(I want to get the idea behind the Batcher Sort, not implement it)? Thanks!
Consider this Python code for printing a list of comma separated values
for element in list:
print element + ",",
What is the preferred method for printing such that a comma does not appear if element is the final element in the list.
ex
a = [1, 2, 3]
for element in a
print str(element) +",",
output
1,2,3,
desired
1,2,3
For a schoolassigment me and some buddies of mine are creating an application that is showing many similarities with the C-Mon & Kypski musicvideo on www.oneframeoffame.com. The application is being developed in Flex.
We want to get a random point of a clip, let it pause so a user can mimic the pose and make a snapshot out of it.
What i managed to do is get a random point of the movie. I did this by getting a random value between 0 and de total duration of the movie.
But what i didn't managed to do is let the screen pause on every 24st of a frame. As the movie concist out of 24FPS. It looks like the the random value of the movie that is being requested is being rounded by the movie itself. As example: There appears to be no difference between the frames requested at 2.40 or 2.41.
It appears it got something to do with keyframing i've read on the Adobe® Flex™ 3.5 Language Reference. The movie is a FLV file and i use the VideoDisplay object to display the movie.
Does someone is familiar with this or knows a solution to my problem?
Thanks in advance
Hi all,
I am looking at using hibernate validator for a requirement of mine. I want to validate a bean where properties may have multiple validation checks. e.g.
class MyValidationBean
{
@NotNull
@Length( min = 5, max = 10 )
private String myProperty;
}
But if this property fails validation I want a specific error code to be associated with the ConstraintViolation, regardless of whether it failed because of @Required or @Length, although I would like to preserve the error message.
class MyValidationBean
{
@NotNull
@Length( min = 5, max = 10 )
@ErrorCode( "1234" )
private String myProperty;
}
Something like the above would be good but it doesn't have to be structured exactly like that. I can't see a way to do this with hibernate validator. Is it possible?
Thanks.
I'm trying to figure out the most efficient way to running a pretty hefty PHP task thousands of times a day. It needs to make an IMAP connection to Gmail, loop over the emails, save this info to the database and save images locally.
Running this task every so often using a cron isn't that big of a deal, but I need to run it every minute and I know eventually the crons will start running on top of each other and cause memory issues.
What is the next step up when you need to efficiently run a task multiple times a minute? I've been reading about beanstalk & pheanstalk and I'm not entirely sure if that will do what I need. Thoughts???
I tried to do it 2 different ways, but neither way worked.
@Component
public class EmailForm{
...
private QuestionDAO questionDAO;
...
@Autowired
public void setQuestionDAO(QuestionDAO questionDAO) {
this.questionDAO = questionDAO;
}
...
Another way:
@Component
public class EmailForm implements ApplicationContextAware {
...
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.questionDAO = (QuestionDAO)applicationContext.getBean("questionDAO");
}
...
Neither way results in questionDAO being injected
Form bean is populated by spring:
@RequestMapping(method = RequestMethod.POST)
public String submit(@Valid final EmailForm emailForm, BindingResult result, final Model model) {
Hi,
Can someone who uses CJ's Commission Detail Service (REST) tell me what a sample XML response is for this query.
None of CJ's Web Services documentation indicates exactly how the XML is formatted and as I don't have any commission payments yet I can only guess the result.
I have a table basically like so
ID | ItemID | Start | End |
---------------------------------------------------------------
1 234 10/20/09 8:34:22 10/20/09 8:35:10
2 274 10/20/09 8:35:30 10/20/09 8:36:27
3 272 10/21/09 12:15:00 10/21/09 12:17:00
4 112 10/21/09 12:20:14 10/21/09 12:21:21
5 15 10/21/09 12:22:39 10/21/09 12:24:15
There are two "clusters" of entries here, 1-2 and 3-5 separated by a gap in time, specifically 30 minutes is what I'm interested in.
What I would like is the first and last rows of the cluster of entries. This is fairly easy to achieve by retrieving all the rows and looping through them in order of start time, but I'd like to have it in SQL if possible.
I'm using SQL Server 2008, thanks.
I have this transparent view that covers the whole screen. I using this view to group objects because I need to run them together around a specific anchor point. Lets call this view transparentView.
At some point, transparentView contains two subviews. Two vertical bars full of icons, one on the left and one on the right of the screen. I need these bars and their icons to respond to touches, so I have to set transparentView setUserInteraction to YES.
The area between the two vertical bars are totally transparent.
transparentView is on top of other views and I need these other views to respond to taps but, the transparent area of transparentView are intercepting the taps and not letting them go thru to the view below.
This transparent view is a UIImageView based class. I have tried to forward taps on that class, using
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.nextResponder touchesBegan: touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self.nextResponder touchesMoved: touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self.nextResponder touchesEnded: touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesEnded:touches withEvent:event];
}
but this is not working.
How can I do that?
thanks.
I have a data.frame in R. It contains a lot of data : gene expression levels from many (125) arrays. I'd like the data in Python, due mostly to my incompetence in R and the fact that this was supposed to be a 30 minute job.
I would like the following code to work. To understand this code, know that the variable path contains the full path to my data set which, when loaded, gives me a variable called immgen. Know that immgen is an object (a Bioconductor ExpressionSet object) and that exprs(immgen) returns a data frame with 125 columns (experiments) and tens of thousands of rows (named genes).
robjects.r("load('%s')"%path) # loads immgen
e = robjects.r['data.frame']("exprs(immgen)")
expression_data = np.array(e)
This code runs, but expression_data is simply array([[1]]).
I'm pretty sure that e doesn't represent the data frame generated by exprs() due to things like:
In [40]: e._get_ncol()
Out[40]: 1
In [41]: e._get_nrow()
Out[41]: 1
But then again who knows? Even if e did represent my data.frame, that it doesn't convert straight to an array would be fair enough - a data frame has more in it than an array (rownames and colnames) and so maybe life shouldn't be this easy. However I still can't work out how to perform the conversion. The documentation is a bit too terse for me, though my limited understanding of the headings in the docs implies that this should be possible.
Anyone any thoughts?
I have a big application covered by more than a thousand tests via rspec.
We just made the choice to redirect any page like :
/
/foo
/foo/4/bar/34
...
TO :
/en
/en/foo
/fr/foo/4/bar/34
....
So I made a before filter in application.rb like so :
if params[:locale].blank?
headers["Status"] = "301 Moved Permanently"
redirect_to request.env['REQUEST_URI'].sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{I18n.locale}#{$2}" }
end
It's working great but ... It's breaking a lot of my tests, ex :
it "should return 404" do
Video.should_receive(:failed_encodings).and_return([])
get :last_failed_encoding
response.status.should == "404 Not Found"
end
To fix this test, I should do :
get :last_failed_encoding, :locale => "en"
But ... seriously I don't want to fix all my test one by one ...
I tried to make the locale a default parameter like this :
class ActionController::TestCase
alias_method(:old_get, :get) unless method_defined?(:old_get)
def get(path, parameters = {}, headers = nil)
parameters.merge({:locale => "fr"}) if parameters[:locale].blank?
old_get(path, parameters, headers)
end
end
... but couldnt make this work ...
Any idea ??
I have two endpoints (xa,ya) and (xb,yb) of two vectors, respectively a and b, originating from a same point (xo, yo). Also, I know that |a|=|b|+s, where s is a constant. I tried to compute the origin (xo, yo) but seem to fail at some point. How to solve this?
I've modified my .htaccess file to have the following statement
RewriteCond $1 !^index.php$
RewriteRule ^/?([^/]+)$ index.php?c=home&m=details&seo=$1 [L,NS]
This allows me to use product URL's like this: http://domain.com/product_name
However, when trying to access a file at the same level as index.php, it always calls the RewriteRule above and errors out.
I need to be able to access files like below, but each URL currently attempts to load index.php.
http://domain.com/about.htm
http://domain.com/terms.htm
http://domain.com/robots.txt
etc
Any suggestions on how I can modify my htaccess file to get this to work correctly?
Write a program to determine whether a computer is big-endian or little-endian.
bool endianness() {
int i = 1;
char *ptr;
ptr = (char*) &i;
return (*ptr);
}
So I have the above function. I don't really get it. ptr = (char*) &i, which I think means a pointer to a character at address of where i is sitting, so if an int is 4 bytes, say ABCD, are we talking about A or D when you call char* on that? and why?
Would some one please explain this in more detail? Thanks.
So specifically, ptr = (char*) &i; when you cast it to char*, what part of &i do I get?
I have a longer running multi-step process using BackgroundWorker and C#. I need to be sure that each step is completed successfully before moving on to the next step. I have seen many references to letting the BackgroundWorker catch errors and canceling from clicking on a Cancel button, but I want to check for an error myself and then gracefully end the process. Do I treat it just like someone clicked the cancel button, or is there another way?
I need to calculate the timestamp of exactly 7 days ago using PHP, so if it's currently March 25th at 7:30pm, it would return the timestamp for March 18th at 7:30pm.
Should I just subtract 604800 seconds from the current timestamp, or is there a better method?