Why is the runtime of the selection algorithm O(n)?

There are several different selection algorithms, from the much simpler quickselect (expected O(n), worst-case O(n2)) to the more complex median-of-medians algorithm (Θ(n)). Both of these algorithms work by using a quicksort partitioning step (time O(n)) to rearrange the elements and position one element into its proper position. If that element is at the index in … Read more

UITableViewCell Selected Background Color on Multiple Selection

All the above answers are fine but a bit to complex to my liking. The simplest way to do it is to put some code in the cellForRowAtIndexPath. That way you never have to worry about changing the color when the cell is deselected. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let … Read more

WPF – How to combine DataTrigger and Trigger?

For anyone else who’s up against this problem, I found a solution that works for me. Of course, I’m still interested to see other interesting answers. Here’s what I did: <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding=”{Binding RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}” Value=”True”/> <Condition Binding=”{Binding IsAvailable}” Value=”False”/> </MultiDataTrigger.Conditions> <Setter TargetName=”Name” Property=”Foreground” Value=”#F00″/> </MultiDataTrigger> There’s nothing special about … Read more

android: smoothScrollToPosition() not working correctly

You probably want to tell the ListView to post the scroll when the UI thread can handle it (which is why yours it not scrolling properly). SmoothScroll needs to do a lot of work, as opposed to just go to a position ignoring velocity/time/etc. (required for an “animation”). Therefore you should do something like: getListView().post(new … Read more

Disable selecting in WPF DataGrid

The clean way would be, to just override the styles of the row and the cell <DataGrid.Resources> <ResourceDictionary> <Style x:Key=”{x:Type DataGridCell}” TargetType=”{x:Type DataGridCell}”> <Setter Property=”Background” Value=”{x:Null}” /> <Setter Property=”BorderBrush” Value=”{x:Null}” /> <Style.Triggers> <Trigger Property=”IsSelected” Value=”True”> <Setter Property=”Background” Value=”{x:Null}” /> <Setter Property=”BorderBrush” Value=”{x:Null}” /> </Trigger> </Style.Triggers> </Style> <Style TargetType=”{x:Type DataGridRow}”> <Setter Property=”Background” Value=”{x:Null}” /> <Setter Property=”BorderBrush” … Read more

Multiple selections in VIM

No, this is not possible without plugins. But you can copy multiple lines into the same buffer, if that solves your problem. To start the ‘Accumulation Buffer’: mark a section to copy in visual mode, press “a to operate on the buffer a with the next command and yank it as usual (y). To add … Read more