Find date range overlaps within the same table, for specific user MySQL

Here is the first part: Overlapping cars per user… SQLFiddle – correlated Query and Join Query Second part – more than one user in one car at the same time: SQLFiddle – correlated Query and Join Query. Query below… I use the correlated queries: You will likely need indexes on userid and ‘car’. However – … Read more

Python – Rounding by quarter-intervals

This is a general purpose solution which allows rounding to arbitrary resolutions. For your specific case, you just need to provide 0.25 as the resolution but other values are possible, as shown in the test cases. def roundPartial (value, resolution): return round (value / resolution) * resolution print “Rounding to quarters” print roundPartial (10.38, 0.25) … Read more

Union of intervals

Sort them by one of the terms (start, for example), then check for overlaps with its (right-hand) neighbor as you move through the list. class tp: def __repr__(self): return “(%d,%d)” % (self.start, self.end) def __init__(self, start, end): self.start = start self.end = end s = [tp(5, 10), tp(7, 8), tp(0, 5)] s.sort(key=lambda self: self.start) y … Read more

C: How to wrap a float to the interval [-pi, pi)

Edit Apr 19, 2013: Modulo function updated to handle boundary cases as noted by aka.nice and arr_sea: static const double _PI= 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348; static const double _TWO_PI= 6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696; // Floating-point modulo // The result (the remainder) has same sign as the divisor. // Similar to matlab’s mod(); Not similar to fmod() – Mod(-3,4)= 1 fmod(-3,4)= -3 … Read more

How can I plot data with confidence intervals?

Here is a plotrix solution: set.seed(0815) x <- 1:10 F <- runif(10,1,2) L <- runif(10,0,1) U <- runif(10,2,3) require(plotrix) plotCI(x, F, ui=U, li=L) And here is a ggplot solution: set.seed(0815) df <- data.frame(x =1:10, F =runif(10,1,2), L =runif(10,0,1), U =runif(10,2,3)) require(ggplot2) ggplot(df, aes(x = x, y = F)) + geom_point(size = 4) + geom_errorbar(aes(ymax = … Read more

Show TimePicker with minutes intervals in android

Use the following the custom class called CustomTimePickerDialog, which I think solve your problem. import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import android.app.TimePickerDialog; import android.content.Context; import android.content.DialogInterface; import android.widget.NumberPicker; import android.widget.TimePicker; public class CustomTimePickerDialog extends TimePickerDialog { private final static int TIME_PICKER_INTERVAL = 5; private TimePicker mTimePicker; private final OnTimeSetListener mTimeSetListener; public CustomTimePickerDialog(Context context, OnTimeSetListener listener, … Read more

tech