sorting

Alphabetical sorting with XSLT

Sample XML: <term> <name>facies</name> <translation language="en">facies</translation> <definition><num>1.</num> cara <num>2.</num> superficie externa, superficie anterior</definition> </term> <term> <name>factores angiógenos</name> <translation language="en">angiogenic factors</translation> <definition>descripció...

List/Arrays - Check Dates

I'm trying to make a program that checks an array to make sure there are four folders with partially same names. So For a date like 0103 (jan 3rd), there should be 0103-1, 0103-2, 0103-3, and 0103-4. Other folders are like 0107-1, 0107-2, 0107-3, 0107-4. How do I go about doing this? I thought about using glob.glob (python) and wildcar...

Removing duplicates from 2d array in Javascript

What would be a nice algorithm to remove dupes on an array like below... var allwords = [ ['3-hidroxitiramina', '3-hidroxitiramina'], ['3-hidroxitiramina', '3-hidroxitiramina'], ['3-in-1 block', 'bloqueo 3 en 1'], ['abacterial', 'abacteriano'], ['abacteriano', 'abacteriano'], ['abciximab', 'abciximab'],...

Comparison function in Python using Lambdas

I am trying to understand lambdas and I get the idea but how do I define multiple conditions for a Point2 [x,y] comparison, so something like: if x1 < x2: -1 if x1 == x2: 0 if x1 > x2: 1 ...

How to sort a DataView in a case-insensitive manner?

I have a DataTable. I'd like to sort its default view by a column name 'city'. I'd like the sort to be case-insensitive. Here is the code I have: DataTable dt = GetDataFromSource(); dt.DefaultView.Sort = "city asc"; MyReport.DataSource = dt.DefaultView; Thanks. ...

How to sort Generic List Asc or Desc ?

I have a generic collection of type MyImageClass, and MyImageClass has an boolean property "IsProfile". I want to sort this generic list which IsProfile == true stands at the start of the list. I have tried this. rptBigImages.DataSource = estate.Images.OrderBy(est=>est.IsProfile).ToList(); with the code above the image stands at the ...

The sort -R command doesn't sort lines randomly in Linux

I can't get --random-sort to work with the sort command on a Fedora Linux-system. Some context information: $ cat /etc/fedora-release Fedora release 7 (Moonshine) $ which sort /bin/sort $ man sort | grep -A 2 '\-R' -R, --random-sort sort by random hash of keys $ man sort | grep -A 3 '\-R' -R, --random-sort ...

preserve whitespace between xsl:sort'd nodes

I'm trying to figure out how to preserve the whitespace nodes between the nodes I'm sorting. Here is an example. Input: <a> <b> <c> <d>world</d> </c> <c> <d>hello</d> </c> </b> <e>some other stuff</e> </a> Desired output: <a> <b> <c> <d>hell...

Sorting Columns in a gridview whose data source is an oracle db

Can anyone tell the function to sort the columns of a gridview in c# asp.net. The gridview is databound to an oracle database. I wanted to click the header of the column to sort the data. i dont know how to refer to the header itself is it using the sender argument of the gridview_sorting method? Thanks ...

How can I sort a List<T> when the user clicks on a table header?

I'm writing an asp.net mvc app and I've get a list of service calls that I display in a table. When the user clicks the table header I want to tell my controller to sort the list by that column. public ActionResult Index(int? page, string sortBy, string sortDirection) { int pageIndex = page == null ? 0 : (int)page - 1; ...

How can you re-arrange items in an array based on its dependencies? and also detect any cyclic dependency

Given the type: class Field{ public string Name{get;set;} public string[] DependsOn{get;set;} } Let's say I have an array of Field items: List<Field> fields = new List<Field>(); fields.Add(new Field() { Name = "FirstName" }); fields.Add(new Field() { Name = "FullName", DependsOn = new[] {"FirstName",...

How do I store orders?

I have an app which has tasks in it and you can reorder them. Now I was woundering how to best store them. Should I have a colomn for the ordernumber and recalculate all of them everytime I change one? Please tell me a version which doesn't require me to update all order numbers since that is very time consuming (from the executions poin...

MySQL based web app: Easiest way for users to choose order or items?

I'm working on something where users can rearrange items, and at a later time, those items need to be displayed in the order chosen. As a simple example, consider a list of items: A, B, C, D, E, F, G. The MySQL table would be something simple: user_id, letter, sortnumber The user is allowed to change the order in incremental steps. ...

C#: Good/Best implementation of Swap method

I read this post about card shuffling and in many shuffling and sorting algorithms you need to swap two items in a list or array. But what does a good and effecient Swap method look like? Lets say for a T[] and for a List<T>. How would you best implement a method that swaps two items in those two? Swap(ref cards[i], ref cards[n]); // ...

Sort <div> elements using jQuery

I have HTML like the following on my website: <div class="groups"> <div class="group"> Group 1 priority: <select> <option value="1.0">1</option> <option value="2.0" selected="selected">2</option> <option value="3.0">3</option> </select> </div> <div class="group"> Group 2 priority: <select> ...

Alphabetically Sort a Java Collection based upon the 'toString' value of its member items.

Assume I have a user defined Java class called Foo such as: public class Foo { private String aField; @Override public String toString() { return aField; } } and a Collection such as: List<Foo> aList; What I am looking to do is to sort the List alphabetically based upon each member's returned '.toString(...

Problem sorting RSS feed by date using XSL

I'm creating a website where I need to show the top 5 records from an RSS feed, and these need to be sorted by date and time. The date fields in the RSS feed are in the following format: "Mon, 16 Feb 2009 16:02:44 GMT" I'm having big problems getting the records to sort correctly - I've tried lots of different code examples I've seen, ...

Best way to calculate dates from results?

I have a database table. It has several hundred entries and each entry is timestamped. I'm looking to only output each day and not have it duplicate any days. Data: 2009-02-04 06:20:27 2009-02-04 06:20:27 2009-02-05 06:20:27 2009-02-07 06:20:27 2009-02-07 06:20:27 2009-02-07 06:20:27 Output should only be (time is irrelevant): 20...

How can I get a subset of a list based on a Datetime key in C#?

I have a list of elements describing events that took place at some time, the time being represented as a Datetime property 'StartTime' on the objects. I now wish to extract a subset of these events containing those elements that are placed in an interval / between two DateTime instances A,B such that StartTime >= A && StartTime <= B. C...

Drupal 5 views -- can I have a random block and a sorted page?

I keep running into the same problem, and I feel like I'm solving it the clunky way. Do you have a better solution? I have a site that with the content type "Staff Bios". I've created a view page that lists all the bios in alphabetical order. I want to have a block that shows just one bio (like a sidebar teaser), and I want the choic...