text:
Q: How to change image source when view model property changes I'm building a WP8 application with MVVM Light and I encountered a silly problem I can't find and easy solution for.
In the XAML page I have the following:
        <Button Command="{Binding PlayCommand}" >
            <Image Source="Images/play.png"/>
        </Button>

When PlayCommand is executed, I change the value of IsPlaying property in the ViewModel to true.
Now, I would want the XAML page to react to the change of IsPlaying and change the source of the Image to "Images/pause.png". In WPF I could do it with DataTriggers (also not convenient), but it doesn't seem to work in WP8. Of cource I could just bind the Image Source to the ViewModel like this, but that beats the entire purpose of MVVM.
    <Button Command="{Binding PlayCommand}" >
        <Image Source="{Binding PlayButtonImage}"/>
    </Button>

I know that there are complex solutions (for example, attached properties, behaviors, etc...), but I figure that there must be a simple one...

A: Maybe a converter class like this one?
public class BoolToIconConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is bool)
        {
            bool isPlaying = (bool)value;
            if (isPlaying)
                return "Images/pause.png";
            else
                return "Images/play.png"
        }
        return "Images/play.png";
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Used like this
<Button Command="{Binding PlayCommand}" >
    <Image Source="{Binding IsPlaying, Converter={StaticResource BoolToIconConverter}}"/>
</Button>

Although I don't think a property in MVVM would break your MVVM pattern, and may even give you better performance than using value converters.

A: There is nothing wrong with the Image property in your ViewModel.

A: You can put a BitmapImage in the Image using the Source property as such:
<Button Command="{Binding PlayCommand}" >
    <Image>
        <Image.Source>
            <BitmapImage UriSource="{Binding ImageUri}"/>
        </Image.Source>
    </Image>
</Button>

You can then bind ImageUri to a notification property on your ViewModel of type Uri.


text:
Q: R data.table, mean number of instances of factor variable, grouped by two other factor variables I'm attempting to use ddply to work with a data.table(dt1).  As an example dt1 is comprised of three, factor columns.  What I need to do is create a fourth numeric column, that has calculated the mean number of incidences of a "1" in the "pres" column, by combination of "walk" and "date".
dt1 <- data.table (walk = as.factor(rep(1:3, each=12)),
               date = as.factor(rep(1:4, 9)),
               pres = as.factor(rbinom(36,1,0.5))
               )

creates a data table like this
> head (dt1)
   walk date pres
1:    1    1    0
2:    1    1    0
3:    1    1    1
4:    1    2    1
5:    1    2    1
6:    1    2    1

and what I hope to end up with is like this
> head (dt1)
   walk date pres  mean
1:    1    1    0   0.33
2:    1    1    0   0.33
3:    1    1    1   0.33
4:    1    2    1   1.00
5:    1    2    1   1.00
6:    1    2    1   1.00

I'm attempting to use the ddply function and think I'm close but have not got the function part correct yet
ddply(dt1, .variables=c("walk","date"), .fun = sum(dt1[, pres] == "1") / length(dt1[,pres])) [ , ]

Any suggestions on how to set the formula correctly, or alternatively a better solution, most welcome.

A: We group by 'walk', 'date', create a new column 'Mean' by assigning (:=) the output of mean from the logical index pres==1.
 dt1[, Mean := mean(pres==1) , by=.(walk, date)]

Or as @Frank mentioned, we can sum the logical index and divide by number of rows (.N)
 dt1[, Mean := sum(pres==1)/.N, by = .(walk, date)]

As the OP used ddply, the equivalent option would be
 library(plyr)
 ddply(dt1, .variables=c('walk', 'date'),  mutate, Mean= mean(pres==1))

Or if we are using dplyr
 library(dplyr)
 dt1 %>%
    group_by(walk, date) %>%
    dplyr::mutate(Mean= mean(pres==1))

A base R option would be
dt1$Mean <- with(dt1, ave(pres==1, walk, date))

redpajama_set_name: RedPajamaStackExchange


text:
Q: In objective-c , how can an object return a different proxy object when itself is assigned as a delegate it implements I have an object which implements various protocols (like 10 different ones).
For example
@interface MyClass <UITableViewDelegate,UITableViewDataSource,UISearchDisplayDelegate,...>

@end

@implementation

/// a whole bunch of methods for the delegates
@end

In order to "clean" things up in this class - I have created helper classes which encapsulates the logic pertaining to those delegates.
so now the new refactored class looks something like
// public interface which looks the same
@interface MyClass <UITableViewDelegate,UITableViewDataSource,UISearchDisplayDelegate,...>

@end

// private interface

@interface MyClass ()

// a bunch of objects which implement those methods
@property (nonatomic,strong) MyUITableviewDelegate *tableViewDelegate;
@property (nonatomic,strong) MyUITableviewDataSource *tableViewDelegate;
@property (nonatomic,strong) MySearchDisplayDelegate *searchDisplayDelegate;
// another bunch of objects which answer to the delegates
@end

@implementation
// all the delegate methods were moved out of here to the class which implements the method

@end

Now when an object of "MyClass" is assigned as a delegate - it should return the runtime object which "answers" to those delegates (for instance if "MyClass" object is assigned as a UITableViewDelegate - the MyUITableviewDelegate should be assigned.
How can this be done?
Must I override the forwardInvocation in the "MyClass" object?

A: You need to implement forwardingTargetForSelector:
- (id)forwardingTargetForSelector:(SEL)aSelector {
    if ([self.tableViewDelegate respondsToSelector:aSelector]) {
        return self.tableViewDelegate;
    }
    // etc

    return [super forwardingTargetForSelector:aSelector];
}


text:
Q: How to prove this josephus problem variation is a np-complete problem? I have a problem that is a Josephus problem variation. It is described below:
There are m cards with number from 1 to m,and each of them has a unique number. The cards are dispatched to n person who sit in a circle. Note that m >= n.
Then we choose the person "A" who sits at the position "p" to out of the circle, just like the Josephus problem does. Next step we skip "k" person at the right of p while k is the number of the card toked by the person "A", and we do the same thing until only one person left in the circle.
Question is given n person and m cards, can we choose n cards and allocate them to the n person, to make that whether start at which position(exclude the first position), the person survival at the end is always the first person in the circle.
For example, m = n = 5, the only solution is (4, 1, 5, 3, 2).
I think this problem is a np-complete problem, but I can't prove it. Anybody has a good idea to find a polynomial time solution or prove it's np-hard?
--- example solutions ---
 2: [ 1,  2]
 2: [ 2,  1]
 3: [ 1,  3,  2]
 3: [ 3,  1,  2]
 4: [ 4,  1,  3,  2]
 5: [ 4,  1,  5,  3,  2]
 7: [ 5,  7,  3,  1,  6,  4,  2]
 9: [ 2,  7,  3,  9,  1,  6,  8,  5,  4]
 9: [ 3,  1,  2,  7,  6,  5,  9,  4,  8]
 9: [ 3,  5,  1,  8,  9,  6,  7,  4,  2]
 9: [ 3,  9,  2,  7,  6,  1,  5,  4,  8]
 9: [ 6,  1,  8,  3,  7,  9,  4,  5,  2]
10: [ 3,  5,  6, 10,  1,  9,  8,  7,  4,  2]
10: [ 4,  5,  2,  8,  7, 10,  6,  1,  9,  3]
10: [ 5,  1,  9,  2, 10,  3,  7,  6,  8,  4]
10: [ 6,  3,  1, 10,  9,  8,  7,  4,  5,  2]
10: [ 8,  5,  9, 10,  1,  7,  2,  6,  4,  3]
10: [10,  5,  2,  1,  8,  7,  6,  9,  3,  4]
11: [ 2,  1, 10, 11,  9,  3,  7,  5,  6,  8,  4]
11: [ 3,  7, 11, 10,  9,  8,  1,  6,  5,  4,  2]
11: [ 3, 11, 10,  9,  8,  1,  7,  2,  4,  5,  6]
11: [ 4,  1, 10,  2,  9,  8,  7,  5, 11,  3,  6]
11: [ 4,  2,  7, 11,  5,  1, 10,  9,  6,  3,  8]
11: [ 4,  7,  2,  3,  1, 10,  9,  6, 11,  5,  8]
11: [ 4,  7,  3,  9, 11, 10,  1,  8,  6,  5,  2]
11: [ 4, 11,  7,  2,  1, 10,  9,  6,  5,  3,  8]
11: [ 5, 11,  3,  9,  8,  7,  6,  1, 10,  4,  2]
11: [ 6,  1, 10,  2,  9,  8,  7,  5, 11,  3,  4]
11: [ 6,  2,  7, 11,  5,  1, 10,  9,  4,  3,  8]
11: [ 6, 11,  1,  3, 10,  2,  7,  5,  4,  9,  8]
11: [ 9,  5,  3,  1, 10,  2,  8,  7, 11,  6,  4]
12: [ 1,  7, 11, 10,  4,  9,  2, 12,  6,  5,  8,  3]
12: [ 3,  7, 12,  2, 11, 10,  9,  1,  6,  5,  4,  8]
12: [ 3,  8, 11,  2, 12,  9,  1,  7,  5, 10,  4,  6]
12: [ 4,  2,  5,  1, 11, 10,  9,  8, 12,  7,  3,  6]
12: [ 4,  3,  7,  6,  1, 11, 10,  9,  8, 12,  5,  2]
12: [ 5,  1,  6, 11,  9,  2, 10,  7, 12,  8,  3,  4]
12: [ 5,  2,  3, 12,  9, 10,  7,  6,  1, 11,  4,  8]
12: [ 5,  7, 12,  2, 10,  9,  8, 11,  1,  4,  6,  3]
12: [ 7,  1,  2,  3,  5,  9, 10,  8, 11,  6, 12,  4]
12: [ 8,  7,  1, 11,  9,  3,  5, 10,  6,  4, 12,  2]
12: [ 8,  7, 11, 10, 12,  3,  1,  9,  6,  5,  4,  2]
12: [12,  3, 11,  5,  1, 10,  8,  7,  6,  4,  9,  2]
12: [12,  7, 11,  1,  9,  3,  2, 10,  6,  5,  4,  8]
13: [ 2,  1,  4,  7, 11,  6,  3, 10, 13,  5,  8, 12,  9]
13: [ 2,  5, 13, 12,  4, 11,  3,  1,  9,  7,  8,  6, 10]
13: [ 2, 13, 12, 11,  3,  1,  9,  4,  8,  7, 10,  5,  6]
13: [ 3,  5,  2,  1, 12,  9, 11, 10,  7,  6, 13,  4,  8]
13: [ 3,  5, 13,  1, 11,  2,  9,  8,  7, 12,  6,  4, 10]
13: [ 4, 13,  3,  1, 12, 11, 10,  9,  7,  2,  5,  6,  8]
13: [ 6,  4,  3,  1, 10, 11, 13,  5,  9, 12,  7,  8,  2]
13: [ 6,  4, 13,  7,  5,  1, 12, 11, 10,  9,  8,  3,  2]
13: [ 6,  7,  3, 13, 12, 11, 10,  2,  1,  9,  5,  4,  8]
13: [ 6,  7, 13, 11,  2, 10,  9,  1,  8, 12,  5,  3,  4]
13: [ 6, 11,  7, 13,  1, 10,  2, 12,  9,  8,  5,  4,  3]
13: [ 7,  3,  2,  1, 11, 10,  9,  8, 13,  5, 12,  4,  6]
13: [ 7,  5, 13,  3, 10, 11,  2,  9,  1,  6,  8,  4, 12]
13: [ 7,  5, 13,  3, 11,  2,  9,  8,  1,  6, 12,  4, 10]
13: [ 7,  5, 13,  3, 11, 12,  2,  1,  9,  8,  6,  4, 10]
13: [ 7,  9,  1, 11,  3, 13,  2, 10, 12,  6,  5,  4,  8]
13: [ 8,  3,  5, 11, 13,  9, 10,  7,  1,  6,  4, 12,  2]
13: [ 8,  3, 13,  1,  5, 11, 10,  9, 12,  7,  6,  4,  2]
13: [ 9,  3, 13,  2, 10,  4,  1,  7,  6,  5, 12, 11,  8]
13: [ 9,  4,  7,  5,  1, 11, 13, 10, 12,  8,  6,  3,  2]
13: [ 9,  5,  4, 13,  2, 11,  8, 10,  1,  7, 12,  3,  6]
13: [ 9,  5, 13,  4, 11,  1,  8,  3,  7, 12,  6, 10,  2]
13: [10,  4,  3,  5, 13,  1,  9, 11,  7,  6,  8, 12,  2]
13: [11,  2,  7,  3, 12,  1, 10,  9,  6,  5, 13,  4,  8]
13: [11, 13,  5,  2, 10,  9,  8,  7,  1,  6,  4,  3, 12]
13: [11, 13,  7,  1, 12,  9,  2,  3, 10,  5,  4,  6,  8]
13: [12,  1,  3,  5, 11, 13,  4, 10,  9,  8,  7,  6,  2]
13: [12,  7, 13,  3, 11,  1,  9,  8,  6,  5, 10,  4,  2]
13: [12, 13,  7, 11,  2,  5,  1,  9, 10,  6,  4,  3,  8]
13: [13,  3,  1, 12, 11,  2,  9, 10,  7,  6,  4,  5,  8]
13: [13,  3,  7,  1,  5, 12,  4, 10,  9,  8, 11,  6,  2]
14: [ 3,  5, 13, 14,  1, 12, 11, 10,  9,  8,  7,  6,  4,  2]
14: [ 3,  9,  1, 13, 11, 10,  2,  4,  7, 14,  6,  8,  5, 12]
14: [ 3, 14,  4, 12, 11,  1,  9,  8,  2, 13,  7,  5, 10,  6]
14: [ 4, 11,  1, 13,  7, 10, 12,  2, 14,  9,  8,  5,  6,  3]
14: [ 4, 14,  2,  5, 13,  1, 12, 11,  7,  6, 10,  9,  3,  8]
14: [ 5,  7,  1, 13, 12, 11, 10,  2,  9,  8, 14,  6,  4,  3]
14: [ 6,  3, 14,  5, 11, 13,  2, 12,  9,  1,  7,  4,  8, 10]
14: [ 6, 14,  1, 12,  5, 13,  2, 11,  9,  7,  8,  4,  3, 10]
14: [ 7,  5, 13, 12,  1, 11,  4, 10,  2, 14,  9,  8,  6,  3]
14: [ 7, 11,  5, 13,  1,  3,  2,  4, 10,  9, 14,  6,  8, 12]
14: [ 7, 14,  1, 13,  2,  5, 11, 12, 10,  9,  8,  4,  3,  6]
14: [ 8,  7,  5, 13,  2, 11,  3,  9, 10, 12,  1, 14,  4,  6]
14: [11,  2, 10,  5,  8,  7,  9,  1, 13, 14, 12,  4,  3,  6]
14: [11,  3, 14,  2, 13,  1, 10,  8,  9,  7,  5, 12,  4,  6]
14: [11,  5,  3, 14,  2,  1, 13, 10,  8,  7,  6, 12,  4,  9]
14: [11, 14,  5,  3, 13,  1, 10,  2,  9,  4,  7,  8, 12,  6]
14: [12,  1, 14,  3, 13,  4, 10,  9,  2,  7,  6,  5, 11,  8]
14: [12, 11,  7,  5, 13,  3,  2, 14,  1,  9,  8,  4,  6, 10]
14: [12, 14,  7, 13,  6,  5, 11,  1, 10,  9,  8,  4,  3,  2]
14: [13,  1,  7,  2, 11,  3,  9, 14,  8,  6,  5, 10,  4, 12]
14: [13, 11,  3,  1,  4,  2,  7, 10,  9,  6, 14, 12,  5,  8]
14: [14,  1, 13,  3, 11,  5, 10,  9,  2,  6,  8,  7,  4, 12]
14: [14, 5, 1, 13, 12, 2, 11, 3, 7, 9, 6, 8, 4, 10]

--- possibly helpful for a mathematical solution ---
I noticed that starting with length 9, at least one solution for every length has a longish sequence of integers that decrement by 1.
 9: [3,  1,  2,                               7, 6, 5,    9, 4, 8]
10: [6,  3,  1,                     10, 9, 8, 7,          4, 5, 2]
11: [3,  7,                     11, 10, 9, 8,             1, 6, 5, 4, 2]
11: [3,                         11, 10, 9, 8,             1, 7, 2, 4, 5, 6]
11: [5, 11,  3,                         9, 8, 7, 6,       1, 10, 4, 2]
12: [4,  2,  5,  1,             11, 10, 9, 8,            12, 7, 3, 6]
12: [4,  3,  7,  6, 1,          11, 10, 9, 8,            12, 5, 2]
13: [6,  4, 13,  7, 5, 1,   12, 11, 10, 9, 8,             3, 2]
14: [3,  5, 13, 14, 1,      12, 11, 10, 9, 8, 7, 6,       4, 2]

A: I noticed that for every length I tested except the very small, at least one solution contains a relatively long run of descending
numbers. So far this answer only considers m = n. Here are a few examples; note that excess is n - run_len:
n = 3, run_len = 2, excess = 1: [1] + [3-2] + []
n = 4, run_len = 2, excess = 2: [4, 1] + [3-2] + []
n = 5, run_len = 2, excess = 3: [4, 1, 5] + [3-2] + []
n = 6, no solution
n = 7, run_len = 1, excess = 6: [5] + [7-7] + [3, 1, 6, 4, 2]
n = 8, no solution
n = 9, run_len = 3, excess = 6: [3, 1, 2] + [7-5] + [9, 4, 8]
n = 10, run_len = 4, excess = 6: [6, 3, 1] + [10-7] + [4, 5, 2]
n = 11, run_len = 4, excess = 7: [3, 7] + [11-8] + [1, 6, 5, 4, 2]
n = 12, run_len = 4, excess = 8: [4, 2, 5, 1] + [11-8] + [12, 7, 3, 6]
n = 13, run_len = 5, excess = 8: [6, 4, 13, 7, 5, 1] + [12-8] + [3, 2]
n = 14, run_len = 7, excess = 7: [3, 5, 13, 14, 1] + [12-6] + [4, 2]
n = 15, run_len = 8, excess = 7: [3, 15, 2] + [13-6] + [1, 5, 4, 14]
n = 16, run_len = 6, excess = 10: [6, 3, 1, 10] + [16-11] + [2, 9, 7, 4, 5, 8]
n = 17, run_len = 8, excess = 9: [2, 5, 17, 15, 14, 1] + [13-6] + [4, 3, 16]
n = 18, run_len = 10, excess = 8: [6, 3, 17, 18, 1] + [16-7] + [5, 4, 2]
n = 19, run_len = 10, excess = 9: [4, 19, 3, 17, 18, 1] + [16-7] + [5, 6, 2]
n = 20, no solution found with run_length >= 10
n = 21, run_len = 14, excess = 7: [3, 21, 2] + [19-6] + [1, 5, 4, 20]
n = 22, run_len = 14, excess = 8: [22, 3, 2, 1] + [20-7] + [5, 21, 4, 6]
n = 23, run_len = 14, excess = 9: [7, 1, 23, 3] + [21-8] + [6, 5, 22, 4, 2]
n = 24, run_len = 16, excess = 8: [6, 5, 24, 2] + [22-7] + [3, 1, 23, 4]
n = 25, run_len = 17, excess = 8: [25, 3, 2, 1] + [23-7] + [5, 24, 4, 6]
n = 26, run_len = 17, excess = 9: [26, 3, 25, 2, 1] + [23-7] + [5, 24, 4, 6]
n = 27, run_len = 20, excess = 7: [3, 27, 2] + [25-6] + [1, 5, 4, 26]
n = 28, run_len = 18, excess = 10: [28, 1, 27, 2, 3] + [25-8] + [6, 5, 7, 4, 26]
n = 29, run_len = 20, excess = 9: [2, 5, 29, 27, 26, 1] + [25-6] + [4, 3, 28]
n = 30, run_len = 23, excess = 7: [30, 5, 2, 1] + [28-6] + [29, 3, 4]
n = 31, run_len = 24, excess = 7: [5, 31, 3] + [29-6] + [1, 30, 4, 2]
n = 32, run_len = 23, excess = 9: [7, 32, 31, 2, 1] + [30-8] + [5, 4, 3, 6]
n = 33, run_len = 26, excess = 7: [3, 33, 2] + [31-6] + [1, 5, 4, 32]
n = 34, run_len = 27, excess = 7: [3, 5, 33, 34, 1] + [32-6] + [4, 2]
n = 35, run_len = 27, excess = 8: [5, 35, 3, 33, 34, 1] + [32-6] + [4, 2]
n = 36, run_len = 26, excess = 10: [35, 7, 3, 1, 36, 2] + [34-9] + [6, 5, 4, 8]
n = 37, run_len = 29, excess = 8: [6, 5, 2, 1] + [35-7] + [36, 37, 3, 4]
n = 38, run_len = 29, excess = 9: [3, 7, 37, 38, 1] + [36-8] + [6, 4, 5, 2]
n = 39, run_len = 32, excess = 7: [3, 39, 2] + [37-6] + [1, 5, 4, 38]
n = 40, run_len = 31, excess = 9: [5, 2, 1] + [38-8] + [3, 7, 40, 4, 6, 39]
n = 41, run_len = 33, excess = 8: [3, 5, 1, 40, 2] + [38-6] + [41, 39, 4]
n = 42, run_len = 33, excess = 9: [42, 3, 41, 2, 1] + [39-7] + [5, 4, 40, 6]
n = 43, run_len = 34, excess = 9: [6, 5, 7, 43, 1] + [41-8] + [42, 4, 3, 2]
n = 44, run_len = 35, excess = 9: [5, 3, 2, 1] + [42-8] + [43, 7, 4, 44, 6]
n = 45, run_len = 38, excess = 7: [3, 45, 2] + [43-6] + [1, 5, 4, 44]
n = 50, run_len = 43, excess = 7: [50, 5, 2, 1] + [48-6] + [49, 3, 4]
n = 100, run_len = 91, excess = 9: [5, 2, 1] + [98-8] + [3, 7, 100, 4, 6, 99]
n = 201, run_len = 194, excess = 7: [3, 201, 2] + [199-6] + [1, 5, 4, 200]

20 is missing from the above table because the run length is at most 10, and is taking a long time to compute. No larger value that I've tested has such a small max run length relative to n.
I found these by checking run lengths from n-1 descending, with all possible starting values and permutations of the run & surrounding elements. This reduces the search space immensely.
For a given n, if the max run in any solution to n is length n-k, then this will find it in O(k! * n). While this looks grim, if k has a constant upper bound (e.g. k <= some threshold for all sufficiently large n) then this is effectively O(n). 'Excess' is what I'm calling k in the examples above. I haven't found any greater than 10, but I don't have a solution yet to n = 20. If it has a solution then its excess will exceed 10.
UPDATE: There are a lot of patterns here.
If n mod 6 is 3 and n >= 9, then [3, n, 2, [n-2, n-3, ..., 6], 1, 5, 4, n-1] is valid.
If n mod 12 is 5 and n >= 17 then [2, 5, n, n-2, n-3, 1, [n-4, n-5, ..., 6], 4, 3, n-1] is valid.
If n mod 20 is 10, then [n, 5, 2, 1, [n-2, n-3, ..., 6], n-1, 3, 4] is valid.
If n mod 60 is 7, 11, 31, or 47, then [5, n, 3, [n-2, n-3, ..., 6], 1, n-1, 4, 2] is valid.
If n mod 60 is 6 or 18 and n >= 18 then [6, 3, n-1, n, 1, [n-2, n-3, ..., 7], 5, 4, 2] is valid.
If n mod 60 is 1, 22, 25 or 52 and n >= 22 then [n, 3, 2, 1], [n-2, n-3, ..., 7], 5, n-1, 4, 6] is valid.
If n mod 60 is 23 then [7, 1, n, 3, [n-2, n-3, ..., 8], 6, 5, n-1, 4, 2] is valid.
If n mod 60 is 14 or 34 then [3, 5, n-1, n, 1, [n-2, n-3, ..., 6], 4, 2] is valid.
If n mod 60 is 24 then [6, 5, n, 2, [n-2, n-1, ..., 7], 3, 1, n-1, 4] is valid
If n mod 60 is 2, 6, 26, 42 and n >= 26 then [n, 3, n-1, 2, 1, [n-3, n-4, ..., 7], 5, n-2, 4, 6] is valid.
If n mod 60 is 16 or 28 then [n, 1, n-1, 2, 3, [n-3, n-4, ..., 8], 6, 5, 7, 4, n-2] is valid.
If n mod 60 is 32 then [7, n, n-1, 2, 1, [n-2, n-3, ..., 8], 5, 4, 3, 6] is valid.
If n mod 60 is 35 or 47 then [5, n, 3, n-2, n-1, 1, [n-3, n-4, ..., 6], 4, 2] is valid.
If n mod 60 is 37 then [6, 5, 2, 1, [n-2, n-1, ..., 7], n-1, n, 3, 4]
If n mod 60 is 38 then [3, 7, n-1, n, 1] + [n-2, n-3, ..., 8] + [6, 4, 5, 2]
If n mod 60 is 40 then [5, 2, 1, [n-2, n-3, ..., 8], 3, 7, n, 4, 6, n-1] is valid
If n mod 60 is 0 and n >= 60 then [3, 5, n, 2, [n-2, n-3, ..., 7], 1, 6, n-1, 4] is valid
If n mod 60 is 7, 19, or 31 and n >= 19 then [4, n, 3, n-2, n-1, 1, [n-3, n-4, ..., 7], 5, 6, 2] is valid
If n mod 60 is 23, 38, or 43 then [7, 3, n, 1, [n-2, n-3, ..., 8], 6, 5, n-1, 4, 2] is a valid solution
If n mod 60 is 14 or 44 and n >= 74 then [3, 5, n-1, n, 1, [n-3, n-4, ..., 6], n-2, 4, 2] is valid.
If n mod 60 is 1 or 49 and n >= 49 then [3, 5, n, 1, [n-2, n-3, ..., 7], 2, n-1, 4, 6] is valid.
If n mod 60 is 6, 18, 30, 42, or 54 and n >= 18 then [n, 3, n-1, 2, 1, [n-3, n-4, ..., 7], 5, 4, n-2, 6] is valid.
If n mod 60 is 10, 18, 38 or 58 and n >= 18 then [n-1, 7, 5, n, 1, [n-2, n-3, ..., 8], 2, 6, 4, 3] is valid.
Currently solved for n mod 60 is any of the following values:
 0,  1,  2,  3,      5,  6,  7,      9,
10, 11,         14, 15, 16, 17, 18, 19,
    21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35,     37, 38, 39,
40, 41, 42, 43, 44, 45,     47,     49,
50, 51, 52, 53, 54,         57, 58

Also,
If n mod 42 is 31 then [n, 3, 2, 1, [n-2, n-3, ..., 8], n-1, 5, 4, 7, 6] is valid.
If n mod 420 is 36 or 396 then [n-1, 7, 3, 1, n, 2, [n-2, n-3, ..., 9], 6, 5, 4, 8] is valid.
--- Example for n=21, using the first pattern listed above, and all starting indices.
1:  [21,  2, 18, 19, 16, 17, 14, 15, 12, 13, 10, 11,  8, 9, 6, 7, 5,  4, 20,  1]
2:  [ 2, 18, 21, 16, 19, 14, 17, 12, 15, 10, 13,  8, 11, 6, 9, 5, 1,  4, 20,  7]
3:  [19, 21, 18,  2, 16, 17, 14, 15, 12, 13, 10, 11,  8, 9, 6, 7, 5,  4, 20,  1]
4:  [18, 21, 19, 17,  2, 15, 16, 13, 14, 11, 12,  9, 10, 7, 8, 1, 5,  4, 20,  6]
5:  [17, 21, 19, 18, 16,  2, 14, 15, 12, 13, 10, 11,  8, 9, 6, 7, 5,  4, 20,  1]
6:  [16, 21, 19, 18, 17, 15,  2, 13, 14, 11, 12,  9, 10, 7, 8, 1, 5,  4, 20,  6]
7:  [15, 21, 19, 18, 17, 16, 14,  2, 12, 13, 10, 11,  8, 9, 6, 7, 5,  4, 20,  1]
8:  [14, 21, 19, 18, 17, 16, 15, 13,  2, 11, 12,  9, 10, 7, 8, 1, 5,  4, 20,  6]
9:  [13, 21, 19, 18, 17, 16, 15, 14, 12,  2, 10, 11,  8, 9, 6, 7, 5,  4, 20,  1]
10: [12, 21, 19, 18, 17, 16, 15, 14, 13, 11,  2,  9, 10, 7, 8, 1, 5,  4, 20,  6]
11: [11, 21, 19, 18, 17, 16, 15, 14, 13, 12, 10,  2,  8, 9, 6, 7, 5,  4, 20,  1]
12: [10, 21, 19, 18, 17, 16, 15, 14, 13, 12, 11,  9,  2, 7, 8, 1, 5,  4, 20,  6]
13: [ 9, 21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  8, 2, 6, 7, 5,  4, 20,  1]
14: [ 8, 21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9, 7, 2, 1, 5,  4, 20,  6]
15: [ 7, 21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9, 8, 6, 2, 5,  4, 20,  1]
16: [ 6, 21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9, 8, 7, 1, 5,  4, 20,  2]
17: [ 1,  5,  2, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9, 8, 7, 6, 4, 19, 20, 21]
18: [ 5,  2, 18, 19, 16, 17, 14, 15, 12, 13, 10, 11,  8, 9, 6, 7, 4,  1, 20, 21]
19: [ 4,  2, 18, 19, 16, 17, 14, 15, 12, 13, 10, 11,  8, 9, 6, 7, 5, 20, 21,  1]
20: [20,  4, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9, 8, 7, 6, 1,  5, 21,  2]

You can observe the same relationship between elements from the decrementing run and other elements for all values of n that the pattern applies to. This isn't a proof, but you can turn this into a proof, though I think the work would need to be done for each pattern separately and it's beyond the scope of what I'm going to spend time on for an S/O question.
--- We can fill in the blanks by using m > n. ---
The pattern [n-1, n, 1, [n-2, n-3, ..., 3], n+5] is valid for n mod 4 is 1 and n >= 9.
The pattern [n, 2, 1, [n-2, n-3, ..., 3], n+4] is valid for n mod 2 is 0 and n >= 6.
With these two, plus what we already found, we get nearly everything. I found these by checking a single replacement value in a limited range.
 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54,     56, 57, 58

If n mod 30 is 29, then [3, n, 2, [n-2, n-3, ..., 4], n-1, n+15) is valid, giving us n mod 60 is 59. We're left with just one unknown: n mod 60 is 55.
...And finally! If n mod 12 is 7 (i.e. n mod 60 is 7, 19, 31, 43, or 55) then [n-1, n, 1, [n-2, n-3, ..., 6], 2, 5, 3, n+4] is valid for all n >= 19.
We now have solutions for all n mod 60, using m=n in most cases, and m=n+15 in the worst case.


text:
Q: Image upload preview rotation (Safari on iOS) I'm developing a fairly complex image uploading function for a website in ASP.Net/Javascript, with a WYSIWYG interface base around an image preview, all done client side before the user hits upload. But I've hit a fundamental snag: I don't really know what the user is seeing, before they even start transforming the image.
The Javascript for creating the preview client side is basically this jQuery bit
$('#inputPhotoUploader').change(function () {
    var image = this.files[0];
    var urlCreator = window.URL || window.webkitURL;
    imageClientURL = urlCreator.createObjectURL(image);

    var previewImage = document.createElement("img");
    previewImage.src = imageClientURL;

    $('#previewContainer').empty();
    $('#previewContainer').append(previewImage);
});

This creates an image in the #previewContainer div based on the file selected in the #inputPhotoUploader, without the user actually uploading anything. Great.
The problem is, that file often contains Exif data concerning rotation. The browser might automatically rotate the preview image based on this data (at least, on my iPhone it does). It might not, like on every desktop browser I've tested.
Eventually the user hits upload, and I get the original file, Exif data and all. But I have no idea how it was displayed to the user. Maybe their browser ignored the Exif data and displayed the image with the "incorrect" rotation, but the user wants it to look exactly that way and that's how my software should display it. Or maybe it was a quick shot with an iPhone, Safari auto-rotated it, and the user expects it to be displayed that way to everyone else because that's what the preview showed.
After the preview is created I do some other fancy image transformations but this basic problem still remains, what did the browser display? Right now the way I see it I need to either determine if the browser is automatically rotating the preview, or somehow make sure that no browser ever does. And I can only come up with ways to do the former, with ugly user agent stuff.
Is there a better way?


text:
Q: how to store NSMutableAttributedString to an array I am trying to customize a string "Add as Event 1"("Event 1" is bold) and then store the string to a mutable array. Here is my codes:
NSString *string1 = @"Add as Event 1";
NSMutableArray *eventsData;
NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc]initWithString:string1];
CTFontRef helvetica = CTFontCreateWithName(CFSTR("Avenir-Book"), 14.0, NULL);
CTFontRef helveticaBold = CTFontCreateWithName(CFSTR("Avenir-Heavy"), 14.0, NULL);
[attrString1 addAttribute:(id)kCTFontAttributeName
               value:(__bridge id)helvetica
               range:NSMakeRange(0, [attrString1 length])];
[attrString1 addAttribute:(id)kCTFontAttributeName
               value:(__bridge id)helveticaBold
               range:NSMakeRange(7, 7)];
eventsData = [[NSMutableArray alloc] initWithObjects: attrString1, nil];

But in the eventsData array I found all constraints with the attrString1 have been stored. But I need only the custom string in the array, because I am gonna pass the value to a label in UITableviewCell later. Here is what I stored in the array:
2015-09-22 13:22:18.574 addEventUI[33834:4374868] Add as {
NSFont = "<UICTFont: 0x7ae6bce0> font-family: \"Avenir-Book\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
}Event 1{
NSFont = "<UICTFont: 0x7ae6bdd0> font-family: \"Avenir-Heavy\"; font-weight: bold; font-style: normal; font-size: 14.00pt";
}

Can anyone tell me how to do it? Thanks very much.

A: I think you're pretty close to what you want.  Create the string and add it to the array as you currently have it***.  Later, if you want to use either the plain string or the attributed string, you can do this...
// assume eventsData has at least one attributed string in it
NSMutableAttributedString *attributedString = eventsData[0];

// assign the plain string to a label like this
myLabel.text = attributedString.string;

// assign it with attributes to a label like this
myLabel.attributedText = attributedString;

***There's some opportunity to improve the code that creates the attributed string and the eventsData array, but I think that's incidental to the main question.


text:
Q: what should i do for https in nginx/express? my purpose...

*

*client ------> 80 port.

*80 ----------> 443 (by nginx, for https)

*443 ---------> 3000 (by nginx)

*express server is waiting on port 3000.

When i tried connecting to the domain name, i just got cannot connect site, domain.com deny your access
nginx settings  - /etc/nginx/sites-available/default
> # HTTP server {
>         listen 80 default_server;
>         listen [::]:80 default_server;
>         server_name domain.com www.domain.com;
>
>         access_log /var/log/nginx/domain.access.log;
>         error_log /var/log/nginx/error.log;
>
>         # redirect to https
>         return 301 https://$server_name$request_uri; }

> # HTTPS server {
>         listen 443 ssl;
>         listen [::]:443 ssl;
>         #server_name domain.com www.domain.com;
>
>         access_log /var/log/nginx/domain.access.log;
>         error_log /var/log/nginx/error.log;
>
>         ssl on;
>
>         # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
>         ssl_certificate /etc/letsencrypt/live/www.domain.com/fullchain.pem;
>         ssl_certificate_key /etc/letsencrypt/live/www.domain.com/privkey.pem;
>
>         ssl_session_timeout 1d;
>         ssl_session_cache shared:SSL:50m;
>         ssl_session_tickets off;
>
>         # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
>         ssl_dhparam /etc/letsencrypt/live/www.domain.com/dhparam.pem;
>
>         # intermediate configuration. tweak to your needs.
>         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
>         ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-R$
>         ssl_prefer_server_ciphers on;
>
>        # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months
>         add_header Strict-Transport-Security max-age=15768000;
>         # OCSP Stapling ---
>         # fetch OCSP records from URL in ssl_certificate and cache them
>         ssl_stapling on;
>         ssl_stapling_verify on;
>
>         # verify chain of trust of OCSP response using Root CA and Intermediate certs
>         ssl_trusted_certificate /etc/letsencrypt/live/www.domain.com/chain.pem;
>
>         resolver 8.8.8.8 8.8.4.4 valid=86400;
>         resolver_timeout 10;
>
>         location / {
>                proxy_set_header Upgrade $http_upgrade;
>                proxy_set_header Host $host;
>                proxy_set_header X-NginX-Proxy true;
>                proxy_set_header X-Real-IP $remote_addr;
>                proxy_set_header X-Forwarded-Proto https;
>                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
>
>                #additional settings
>                proxy_read_timeout 300;
>                proxy_connect_timeout 300;
>
>                proxy_pass http://localhost:3000;
>                proxy_redirect off;
>                proxy_http_version 1.1;
>        } }

nodejs settings
require('@babel/polyfill');
const app = require('./app');
const debug = require('debug')('learn-express:server');
const http = require('http');
require('dotenv').config();

const port = normalizePort(process.env.http_port);
app.listen(port, () => {
         console.log('Server is running on port '+port);
});


text:
Q: NgbCarousel select does not switch the slide I'm trying to create a thumbnails row to switch slides of the carousel.
The click event is working, the carousel is located correctly - I put some breakpoints in the NgbCarousel code, the passed slide id is correct and it works up to the very switching of the slide. However the slide switching is not happening.
Carousel itself works just fine - both the arrows and indicators.
Angular 6.1.0
Ng-bootstrap 3.2.0
UPDATE
It started working after reinstalling node modules. Though it's very laggy (10 sec for img switch with no additional network request), but that's a different story.
Template:

<ngb-carousel #clotheCarousel="ngbCarousel" *ngIf="pics"
  showNavigationArrows="true"
  showNavigationIndicators="true"
  interval="0">
  <ng-template ngbSlide *ngFor="let pic of pics" id="{{ stripSlash(pic.public_id) }}">

  </ng-template>
</ngb-carousel>

Component:
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import _ from 'lodash';
import { NgbCarousel } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-clothe-gallery',
  templateUrl: './clothe-gallery.component.html',
  styleUrls: ['./clothe-gallery.component.css']
})
export class ClotheGalleryComponent implements OnInit {
  @Input() pics: object[];
  @Input() private thumbWidth: number = 500;
  @Input() private thumbHeight: number = 500;
  @Input() private iconWidth: number = 100;
  @Input() private iconHeight: number = 100;
  @Input() private getCurrent: object;
  // @Output() slide = new EventEmitter();
  @ViewChild(NgbCarousel) carousel: NgbCarousel;
  private currentSlide: string;
  LOG: string = 'clotheGallery';

  constructor() { }

  ngOnInit() {
    console.log(this.LOG, this.pics);
    if (this.pics && this.pics.length) {
      this.currentSlide = this.pics[0]['public_id'];
    }
    // this.slide.emit({
    //   current: this.currentPic
    // })
  }

  onSlideEvent(event) {
    // console.log('event', event);
    // this.currentSlide = event.current;
    // this.slide.emit({
    //   current: this.currentPic
    // })
  }

  get currentPic() {
    return this.currentSlide;
  }

  getThumbUrl(pic) {
    return ClotheGalleryComponent.insertResizeParams(pic, this.thumbWidth, this.thumbHeight);
  }

  getIconUrl(pic) {
    return ClotheGalleryComponent.insertResizeParams(pic, this.iconWidth, this.iconHeight);
  }

  switchPic(pic) {
    console.log(this.LOG, 'switchPic', this.stripSlash(pic.public_id), this.carousel);
    this.carousel.select(this.stripSlash(pic.public_id));
  }

  stripSlash(item) {
    return item.replace('\/', '');
  }

  static insertResizeParams(pic, thumbWidth, thumbHeight): string {
    if (!pic || !pic.url) {
      return '';
    }
    let replace = 'upload';
    let params = `${replace}/w_${thumbWidth},h_${thumbHeight},c_fit`;
    return pic.url.replace(replace, params);
  }

}

A: Try to change:
@ViewChild(NgbCarousel) carousel: NgbCarousel;

to:
@ViewChild("clotheCarousel") carousel: NgbCarousel;

And use (but it may require index id):
this.carousel.activeId = this.stripSlash(pic.public_id);

instead of:
this.carousel.select(this.stripSlash(pic.public_id));

As well as:
<ng-template ngbSlide *ngFor="let pic of pics" id=" stripSlash(pic.public_id)">

A: I'am not sure about your ViewChild(NgbCarousel). Are you sure your console.log(this.carousel) show the carousel? By the way you can use the reference variable in your function

and
//use carousel, not this.carousel
switchPic(carousel:any,pic) {
    console.log(this.LOG, 'switchPic', this.stripSlash(pic.public_id), carousel);
    carousel.select(this.stripSlash(pic.public_id));
  }

A: It's a bit tricky, the selector is 'ngb-slide-X' with X the current index from 0.
Let's say you have a table, and when you click on a row, you want to update a picture.

@ViewChild(NgbCarousel, { static: true }) carousel: NgbCarousel;

...

click(id: number, i: number) {
  this.carousel.select('ngb-slide-' + i);
}

    {{ i + 1 }}
    {{ signature.date | date:'shortDate' }}
    {{ signature.client }}
    {{ signature.chauffeur }}
    {{ signature.signataire }}

.....

 <ngb-carousel id="carousel" [showNavigationArrows]="false" [showNavigationIndicators]="false">
  <ng-template ngbSlide *ngFor="let signature of (signatures$ | async)">

{{ signature.caption }}

  </ng-template>
</ngb-carousel>


text: Q: JWT Token authentication in github social authentication in Django(Note: Use django allauth) In a django project i created a user login using github social authentication by using django allauth. i want to implement JWT token authentication in it. How can i do it? If any one have any idea please share.


text:
Q: SUblimeText2 plugin for automatic CSS class creation? I was looking for some plugin that could easily generate a CSS statement from my HTML template. So The moment I create a DOM element, should be possible to generate a CSS statement   to access that DOM element.
Could be a simple one that just adds the whole DOM order from my outter element to the desire element. Any suggestions are welcome. Thanks

A: I'm finding the same like you, if you know something, tell me please.
But you can try it:
http://lab.xms.pl/css-generator/
I hope you can use it, @artdias90


text:
Q: jQuery ui Slider for Background and Font Colors I have a problem regarding my new site design prospect, and it involves using some jQuery and jQueryUI (mainly SliderUi) and some css manipulation.
Everytime I slide the #slider, the width of .left will then update depend on (ui.value from 1-100 + '%'), from here slide + background transition is happening already,
My question is is there any possible way to manipulate the color of texts depending on slider's treshold or value? if yes, can you suggest how can I come up into something like this?
Snippet below.
Thanks in advance!

$(document).ready(function() {
  $( "#slider" ).slider({
    max: 101,
    min:1,
    value: 51,
    slide: function(event,ui) {
      var percentage = (ui.value)-1;
      $('.left').css("width",percentage +'%');
    }
  });
});
#slider {z-index: 5;background: #666; }
.left, .right {positioackgrn:absolute; top: 0; left: 0; height: 100vh;}
.left {background: #000; width: 50%; z-index: 1;}
.right {background: #fff;  z-index: -1; width: 100%;}
.main-content {z-index: 3; position: absolute; top: 0; left: 0; width: 100%;}
h3 {color: blue; text-align: center; margin-top: 30px;}
<link href="https://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet"/>

A part of my font must change color depending on slider-ui threshold

A: Update!
http://jsfiddle.net/lsubirana/7od3sfrr/1/
HTML:

My font color must change depending on slider-ui threshold

My font color must change depending on slider-ui threshold

CSS:
.left, .right {position:absolute; top: 0; left: 0; height: 100vh;overflow:hidden;}
.left h3 {color: white; text-align: center; margin-top: 30px;width:100vw;}
.right h3 {color: black; text-align: center; margin-top: 30px;width:100vw;}

Original Answer:
One method to obtain what you are looking for is to pass the slider percentage to a function that can return you an rgb color value. The following page shows how to create rainbows in javascript and I believe can be applied in this case:
http://krazydad.com/tutorials/makecolors.php
$(document).ready(function() {
  $( "#slider" ).slider({
    max: 101,
    min:1,
    value: 51,
    slide: function(event,ui) {
      var percentage = (ui.value)-1;
      $('.left').css("width",percentage +'%');
      $('h3').css('color', rgb(percentage));
    }
  });
});

function rgb(p){
    var frequency = .08;
       r = Math.sin(frequency*p + 0) * 127 + 128;
       g = Math.sin(frequency*p + 2) * 127 + 128;
       b = Math.sin(frequency*p + 4) * 127 + 128;
     return  'rgb(' + Math.round(r) + ',' + Math.round(g) + ',' + Math.round(b) + ')';
}

http://jsfiddle.net/lsubirana/376ow969/


text:
Q: How do you set default attribute values for a custom pivot table? I am trying to set default values for my pivot table intermediate attributes.
I would expect the $attributes property to work with Pivot classes the same as it does with Model classes, since Pivot extends Model. However that does not seem to be the case, because the property seems to have no effect and the defaults are never assigned.
class Client_orm extends Model
{
    public function ranks()
    {
        return $this->belongsToMany( 'Rank_orm', 'diy_client_rank', 'client_id', 'rank_id' )
                    ->using( 'Client_rank_orm' )
                    ->withPivot( 'thedate', 'notes' );
    }
}

class Rank_orm extends Model
{
    public function clients()
    {
        return $this->belongsToMany( 'Client_orm', 'diy_client_rank', 'rank_id', 'client_id' )
                    ->using( 'Client_rank_orm' )
                    ->withPivot( 'thedate', 'notes' );
    }
}

class Client_rank_orm extends Pivot
{
    protected $attributes = array(
        'thedate' => 'some default value',
        'notes' => 'some default value',
    );
}

I would expect that with this code, any omitted pivot table attributes would automatically be set with the defaults. However, I am getting the following Illuminate\Database\QueryException when the attributes are omitted:
General error: 1364 Field 'thedate' doesn't have a default value
I realize I could alter the SQL structure to accept NULL values or set defaults, but that would be a last resort if there is no other way to set defaults through model definitions.
Any help would be appreciated!

A: Turns out this one still hasn't been implemented.
There is a closed proposal for this: https://github.com/laravel/ideas/issues/872
Currently you can only use wherePivot() feature which actually sets default attributes but it's main purpose is filtering, so you still can not set defaults without filtering which is pretty weird as for me.
https://github.com/laravel/framework/pull/22867


text:
Q: Code igniter large query results result_array() result I am looking at this.
I have queries that return up to 10,000 rows and usually fills up the memory
I am currently doing:
$this->db->get()->result_array();

Is there a way to not load all of the data into memory and use some sort of cursor? It seems result and result array are both arrays. (one is array of objects other is an array of arrays)

A: If you are using Active Record, which I would personally recommend, limit() should achieve what you are looking for.
$this->db->limit();
Can also use in this way, slightly easier and less lines of code:
$query = $this->db->get('Table_Name', 50); //syntax db->get('Table',limit_val);
return $query->result();

Also can return a limit with an offset:
$this->db->limit(10, 20); // Second parameter lets you set a result offset

Link for more help on Active Record Query's
https://www.codeigniter.com/userguide2/database/active_record.html#select

A: Mysql offset is the pointer you are looking for.
You can use it like:
    $this->db->get(tableName,10,20);

The second parameter and the third one help you to set limit and offset .
Here are more details


text:
Q: Print the values returned by findbyId on an ejs page I was creating an ecommerce where I had a page where all the products are present, and when you click on a product another page opens that contains more information about that product.
So, when I click on a product button, I take the ID of that product so that I can go and look in mongodb atlas for that document that contains that information.
Through findbyid I can get the document that has that id, in fact if I do a console.log (items.name) I can get that field.
But when I want to go to fill the windowpistacchio.ejs page, I always remain on the same page where all the products are present and I get this error:
items.forEach is not a function
at eval ("C:\Users\batticani\Desktop\Server\views\windowpistacchio.ejs":12:14)
at windowpistacchio (C:\Users...\Desktop\Server\node_modules\ejs\lib\ejs.js:703:17)
at tryHandleCache (C:\Users...\Desktop\Server\node_modules\ejs\lib\ejs.js:274:36)
at View.exports.renderFile [as engine] (C:\Users...\Desktop\Server\node_modules\ejs\lib\ejs.js:491:10)
at View.render (C:\Users...\Desktop\Server\node_modules\express\lib\view.js:135:8)
at tryRender (C:\Users...\Desktop\Server\node_modules\express\lib\application.js:657:10)
at Function.render (C:\Users...\Desktop\Server\node_modules\express\lib\application.js:609:3)
at ServerResponse.render (C:\Users...\Desktop\Server\node_modules\express\lib\response.js:1039:7)
at C:\Users...\Desktop\Server\app.js:93:8
at C:\Users...\Desktop\Server\node_modules\mongoose\lib\model.js:5095:18

//model
var mongoose = require('mongoose');

var imageSchema = new mongoose.Schema({

    name: String,
    desc: String,
    img:
    {
        data: Buffer,
        contentType: String
    }
});

//Image is a model which has a schema imageSchema

module.exports = new mongoose.model('Image', imageSchema);
//windowpistacchio.ejs

<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <% items.forEach(image=>{ %>

            <img src="data:image/<%=image.img.contentType%>;base64,
                    <%=image.img.data.toString('base64')%>" id">

                    <%= image.name %>

                    <%= image.desc %>

        <% }) %>

//server

const express = require('express')
const app = express()

var bodyParser = require('body-parser');
var mongoose = require('mongoose')

var fs = require('fs');
var path = require('path');
require('dotenv/config');

// Static Files
app.use(express.static('public'));

app.use('/css', express.static(__dirname + 'public/css'))
app.use('/js', express.static(__dirname + 'public/js'))
app.use('/img', express.static(__dirname + 'public/img'))

mongoose.connect(process.env.MONGO_URL,
    { useNewUrlParser: true, useUnifiedTopology: true }, err => {
        console.log('connected')
    });

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

// Set View's
app.set('views', './views');
app.set('view engine', 'ejs');

app.get('', (req, res) => {
    res.render('home');
})

var multer = require('multer');

var storage = multer.diskStorage({
    destination: (req, file, cb) => {
        cb(null, 'uploads')
    },
    filename: (req, file, cb) => {
        cb(null, file.fieldname + '-' + Date.now())
    }
});

var upload = multer({ storage: storage });

// Step 6 - load the mongoose model for Image

var imgModel = require('./model');

app.get('/pistacchio.ejs', (req, res) => {
    imgModel.find({}, (err, items) => {
        if (err) {
            console.log(err);
            res.status(500).send('An error occurred', err);
        }
        else {
            res.render('pistacchio', { items: items });
        }
    });
});

app.post('/prodotto', (req, res) => {
    var valore = req.body.myData;
    console.log(valore)
    console.log('result' + valore.toString())

    var hexString = parseInt(valore);
    /*
    console.log(mongoose.Types.ObjectId.isValid(hexString));
    */
    const id = valore.trim();
    imgModel.findById(id, function (err, items) {
        if (err) {
            console.log(err);
        }
        else {
            res.render('windowpistacchio', { items: items})

        }
    });

})

app.all('*', (req, res) => {
    res.status(404).send('
Pagina non trovata
')
})

app.listen(4000)


text:
Q: Based space, commuting in diagram up to homotopy, dual Barratt-Puppe sequence. For a based map $f : X \to Y$, define the "homotopy fiber" $Ff$ to be$$Fd = X \times_f PY = \{(x, \chi) : f(x) = \chi(1)\} \subset X \times PY.$$Equivalently, $Ff$ is the pullback displayed in the diagram

where $\pi(x, \chi) = x$. As a pullback of a fibration, $\pi$ is a fibration.
If $\rho: Nf \to f$ is defined by $\rho(x, \chi) = \chi(0)$, then $f = \rho \circ \nu$, where $\nu(x) = (x, c_{f(x)})$, and $Ff$ is the fiber $\rho^{-1}(*)$. Thus the homotopy fiber $Ff$ is constructed by first replacing $f$ by the fibration $\rho$ and then taking the actual fiber.
Let $\iota: \Omega Y \to Ff$ be the inclusion specified by $\iota(\chi) = (*, \chi)$. The sequence$$\dots \to \Omega^2 X \overset{\Omega^2 f}{\longrightarrow} \Omega^2Y \overset{-\Omega\iota}{\longrightarrow} \Omega Ff \overset{-\Omega\pi}{\longrightarrow} \Omega X \overset{-\Omega f}{\longrightarrow} \Omega Y \overset{\iota}{\to} Ff \overset{\pi}{\to} X \overset{f}{\to} Y$$is called the fiber sequence generated by the map $f$; here$$(-\Omega f)(\zeta)(t) = (f \circ \zeta)(1 - t) \text{ for }\zeta \in \Omega X.$$These "long exact sequences of based spaces" also give rise to long exact sequences of pointed sets, covariantly.

Theorem. For any based space $Z$, the induced sequence$$\dots \to [Z, \Omega F f] \to [Z,\Omega X] \to [Z, \Omega Y] \to [Z, Ff] \to [Z, X] \to [Z, Y]$$is an exact sequence of pointed sets, or of groups to the left of $[Z, \Omega Y]$, or of Abelian groups to the left of $[Z, \Omega^2Y]$.

Exactness is clear at the first stage. To see this, consider the diagram

Here $h: c_* \simeq f \circ g$, and we view $h$ as a map $Z \to PY$. Thus we check exactness by using any given homotopy to lift $g$ to the fiber.
I claim that, up to homotopy equivalence, each consecutive pair of maps in my fiber sequence is the composite of a map and the projection from its fiber onto its source. This will imply the source. I observe that, that for any map $f$, interchange of coordinates gives a homeomorphism$$\Omega F f \cong F(\Omega f)$$such that the following diagram commutes:

Here $\tau$ is obtained by interchanging the loop coordinates and is homotopic to − \text{id}. We have $\iota(f)$, $\pi(f)$, etc., to indicate the maps to which the generic constructions $\iota$ and $\pi$ are applied. Using this inductively, we see that we need only verify our claim for the two pairs of maps $(\iota(f), \pi(f))$ and $(-\Omega f, \iota(f))$.
Anyways, one key step in finishing the proof: I need that the right triangle commutes and the left triangle commutes up to homotopy in the following diagram.

My question is, what is the easiest way to see that the two triangles commute up to homotopy? Thanks in advance.

A: First, we show that the right triangle commutes up to homotopy. Considering the fiber sequence$$F(f) \overset{\pi(f)}{\to} X \overset{f}{\to} Y,$$we want to show that the inclusion of the strict fiber of $\pi(f)$ into its homotopy fiber $F(\pi(f))$ is a homotopy equivalence making the right triangle commute, where$$\iota: \Omega Y \to F(f), \text{ }\iota(\gamma) = (x_0, \gamma) \in F(f) = X \times_Y PY.$$The strict fiber of $\pi(f)$ is the subset of $F(f)$,$$(\pi(f))^{-1}(x_0) = \{(x_0, \gamma) :  \gamma(0) = y_0,\,\gamma(1) = f(x_0) = y_0\} \cong \Omega Y,$$and the composite $\Omega Y \to F(\pi(f)) \to F(f)$ is$$\gamma \mapsto (\iota(\gamma),\,\text{constant path at the basepoint of }F(f)) \mapsto \iota(\gamma).$$The inclusion of the strict fiber $\phi: \Omega Y \overset{\simeq}{\to} F(\pi(f))$ is a homotopy equivalence, since $\pi(f)$ is a fibration (and using this).
Now, we show that the left triangle commutes up to homotopy. The homotopy we require is$$H: \Omega X \times I \to F(\pi(f)),\text{ }(\gamma, s) \mapsto ((*, (f \circ \gamma)(1 - t)|_{[0, 1-s]}), \gamma|_{[1 - s, 1]}).$$This is $\phi \circ (-\Omega f)$ at time $0$ and $i \circ \pi(f)$ at time $1$, so we are done.


text:
Q: Adding Environment Variable in Windows 7 I am trying to use CMake and I need to add an environment variable GSL_ROOT_DIR in windows 7, so that %GSL_ROOT_DIR%\include contains the GSL header files and %GSL_ROOT_DIR%\lib contains the GSL libraries.
Could you tell me exactly how can I do that?

A: *

*Press the start button.  (alternatively: windows key + r, then sysdm.cpl)

*right click "Computer" then click properties.

*Click advanced system settings.

*Click Environment variables.

*Add the variable you need + the correct path.

EDIT:
point %GSL_ROOT_DIR% to the base directory of where you extracted the GSL library. I.e. if you downloaded the developer files from here and extracted it to c:\libs\gsl\ then your %GSL_ROOT_DIR% should be "C:\libs\gsl" (if you look at the zip file, it contains both an include, and a lib folder).


text:
Q: DotNetNuke Empty Project Error I'm working On my first DotNetNuke project and when I create new one I got this list of error on first Compile:
    Warning 1   Namespace or type specified in the Imports 'DotNetNuke.Entities.Modules' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Components\FeatureController.vb 11  9   DNNModule1
Warning 2   Namespace or type specified in the Imports 'DotNetNuke.Services.Search' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Components\FeatureController.vb 12  9   DNNModule1
Warning 3   Namespace or type specified in the Imports 'DotNetNuke.Entities.Modules' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\DNNModule1ModuleBase.vb 11  9   DNNModule1
Error   4   Type 'PortalModuleBase' is not defined. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\DNNModule1ModuleBase.vb 24  14  DNNModule1
Warning 5   Namespace or type specified in the Imports 'DotNetNuke.Entities.Modules' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\DNNModule1SettingsBase.vb   11  9   DNNModule1
Error   6   Type 'ModuleSettingsBase' is not defined.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\DNNModule1SettingsBase.vb   24  14  DNNModule1
Warning 7   Namespace or type specified in the Imports 'DotNetNuke' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Data\DataProvider.vb    11  9   DNNModule1
Error   8   'Framework' is not declared. It may be inaccessible due to its protection level.    c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Data\DataProvider.vb    36  33  DNNModule1
Warning 9   Namespace or type specified in the Imports 'DotNetNuke.Entities.Modules.Actions' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Edit.ascx.vb    10  9   DNNModule1
Warning 10  Namespace or type specified in the Imports 'DotNetNuke.Entities.Modules' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Edit.ascx.vb    11  9   DNNModule1
Warning 11  Namespace or type specified in the Imports 'DotNetNuke.Services.Exceptions' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Edit.ascx.vb    12  9   DNNModule1
Warning 12  Namespace or type specified in the Imports 'DotNetNuke.Services.Localization' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.    c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Edit.ascx.vb    13  9   DNNModule1
Error   13  Event 'Load' cannot be found.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Edit.ascx.vb    39  86  DNNModule1
Error   14  'Exceptions' is not declared. It may be inaccessible due to its protection level.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Edit.ascx.vb    43  13  DNNModule1
Warning 15  Namespace or type specified in the Imports 'Microsoft.ApplicationBlocks.Data' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.    c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Providers\DataProviders\SqlDataProvider\SqlDataProvider.vb  13  9   DNNModule1
Warning 16  Namespace or type specified in the Imports 'DotNetNuke.Common.Utilities' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Providers\DataProviders\SqlDataProvider\SqlDataProvider.vb  15  9   DNNModule1
Warning 17  Namespace or type specified in the Imports 'DotNetNuke.Framework.Providers' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Providers\DataProviders\SqlDataProvider\SqlDataProvider.vb  16  9   DNNModule1
Error   18  Type 'ProviderConfiguration' is not defined.    c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Providers\DataProviders\SqlDataProvider\SqlDataProvider.vb  43  43  DNNModule1
Error   19  Type expected.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Providers\DataProviders\SqlDataProvider\SqlDataProvider.vb  56  32  DNNModule1
Error   20  'Config' is not declared. It may be inaccessible due to its protection level.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Providers\DataProviders\SqlDataProvider\SqlDataProvider.vb  61  33  DNNModule1
Error   21  'DotNetNuke' is not declared. It may be inaccessible due to its protection level.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Providers\DataProviders\SqlDataProvider\SqlDataProvider.vb  121 20  DNNModule1
Warning 22  Namespace or type specified in the Imports 'DotNetNuke' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Settings.ascx.vb    10  9   DNNModule1
Warning 23  Namespace or type specified in the Imports 'DotNetNuke.Services.Exceptions' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Settings.ascx.vb    11  9   DNNModule1
Error   24  sub 'LoadSettings' cannot be declared 'Overrides' because it does not override a sub in a base class.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Settings.ascx.vb    47  26  DNNModule1
Error   25  Reference to a non-shared member requires an object reference.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Settings.ascx.vb    49  17  DNNModule1
Error   26  'ProcessModuleLoadException' is not declared. It may be inaccessible due to its protection level.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Settings.ascx.vb    62  13  DNNModule1
Error   27  sub 'UpdateSettings' cannot be declared 'Overrides' because it does not override a sub in a base class. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Settings.ascx.vb    75  26  DNNModule1
Error   28  Type 'Entities.Modules.ModuleController' is not defined.    c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Settings.ascx.vb    77  35  DNNModule1
Error   29  'ProcessModuleLoadException' is not declared. It may be inaccessible due to its protection level.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\Settings.ascx.vb    87  13  DNNModule1
Warning 30  Namespace or type specified in the Imports 'DotNetNuke' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    10  9   DNNModule1
Warning 31  Namespace or type specified in the Imports 'DotNetNuke.Entities.Modules.Actions' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    11  9   DNNModule1
Warning 32  Namespace or type specified in the Imports 'DotNetNuke.Entities.Modules' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    12  9   DNNModule1
Warning 33  Namespace or type specified in the Imports 'DotNetNuke.Services.Exceptions' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    13  9   DNNModule1
Warning 34  Namespace or type specified in the Imports 'DotNetNuke.Services.Localization' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.    c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    14  9   DNNModule1
Error   35  Type 'IActionable' is not defined.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    29  16  DNNModule1
Error   36  Event 'Load' cannot be found.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    40  86  DNNModule1
Error   37  'Exceptions' is not declared. It may be inaccessible due to its protection level.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    44  13  DNNModule1
Error   38  Type 'ModuleActionCollection' is not defined.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    59  49  DNNModule1
Error   39  Type 'IActionable' is not defined.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    59  83  DNNModule1
Error   40  Type 'ModuleActionCollection' is not defined.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    61  32  DNNModule1
Error   41  'GetNextActionID' is not declared. It may be inaccessible due to its protection level.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    62  25  DNNModule1
Error   42  'Localization' is not declared. It may be inaccessible due to its protection level. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    62  42  DNNModule1
Error   43  'LocalResourceFile' is not declared. It may be inaccessible due to its protection level.    c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    62  79  DNNModule1
Error   44  'Entities' is not declared. It may be inaccessible due to its protection level. c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    62  99  DNNModule1
Error   45  'EditUrl' is not declared. It may be inaccessible due to its protection level.  c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    62  161 DNNModule1
Error   46  'DotNetNuke' is not declared. It may be inaccessible due to its protection level.   c:\users\administrateur\documents\visual studio 2012\Projects\DNNModule1\DNNModule1\View.ascx.vb    62  179 DNNModule1
Warning 47  Could not resolve this reference. Could not locate the assembly "DotNetNuke". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.   DNNModule1
Warning 48  Could not resolve this reference. Could not locate the assembly "Microsoft.ApplicationBlocks.Data". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. DNNModule1
Warning 49  The referenced component 'DotNetNuke' could not be found.   DNNModule1
Warning 50  The referenced component 'Microsoft.ApplicationBlocks.Data' could not be found.     DNNModule1

A: If you are using my templates http://christoctemplate.codeplex.com be sure to follow the DNN development environment setup instructions http://www.christoc.com/tutorials/aid/1
The templates follow a very specific format for development that has been tweaked after many years of doing DNN development, if you follow that format you'll find DNN development a lot easier.

A: This could also be due to you having a project that's compiling against an older version of .Net than DNN.  For example, your project is .Net 3.5 and the version that DNN is compiled against is .Net 4.0.

A: It looks like the project was not able to find DotNetNuke.dll and Microsoft.ApplicationBlocks.Data.dll.
Look at your references section and you should see warning symbols on those two refefences.  Simply remove them and add references with the proper path.
OR - Ideally use NuGet to grab the package - http://mitchelsellers.com/blogs/2013/07/25/enterprise-extension-development-with-dnn-part-two.aspx

A: I have the same problem and now its resolved
Remove references of DotNetNuke, DotNetNuke.web and Microsoft.ApplicationBlocks.Data.dll than navigate to DNN website that you have configured in IIS something like dnndev.me go to bin folder and find these references just add them and your problem will be solved


text:
Q: Difference between SUM(CASE...) and CASE WHEN ... THEN SUM(...) I came across expression (Postgres):
SELECT
  ...,
  CASE WHEN colXX in (...) THEN sum(colYY) END
FROM tbl
WHERE ...
GROUP BY ..., colXX;

It blew my mind. OK, it has sense if there is GROUP BY for CASE WHEN.
Can anyone confirm that using aggregation inside of CASE WHEN is some proprietary SQL extension?
I usually use such form:
SELECT
  ...,
  sum(CASE WHEN colXX in (...) THEN colYY END)
FROM tbl ...;

which works even if colXX isn't in GROUP BY and it has clear semantic.
Also PostgreSQL and HSQLDB has fancy syntax for previous form:
SELECT
  ...,
  sum(colYY) FILTER (WHERE colXX in (...))
FROM tbl ...;

So my question is: which standard or proprietary extensions define aggregation inside CASE and what is the semantic of such expression and what restrictions are in affect when such construction is used?

A: All three of your syntaxes are ISO/ANSI standard.  The third, using filter is only available in a small number of databases (Postgres, the most recent version of SQLite, and some others).
These do exactly the same thing:
sum(colYY) FILTER (WHERE colXX in (...))
sum(CASE WHEN colXX in (...) THEN colYY END)

They sum colYY on rows where the condition is met.  These require that no mentioned columns (neither colXX nor colYY) be in the GROUP BY clause.  In fact, these would normally not be used if either were in the GROUP BY.
This:
(CASE WHEN colXX in (...) THEN sum(colYY) END)

is quite different.  It requires that colXX be in the GROUP BY.  It will calculate the sum on any rows where the colXX condition is true.  Other rows will have a value of NULL.  In my experience, this version is less commonly needed then the other two.
Here is a db<>fiddle that illustrates what is happening.


text:
Q: Quartz single job multiple triggers with specific start times does not work I'm trying to write a simple program which runs the same job at specific date times, the list of date times from a input file and here is my code:
SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();

sched.start();

Map<JobDetail, List<Trigger>> jobAndTriggers = new HashMap<JobDetail, List<Trigger>> ();
List<Trigger> triggers = new ArrayList<Trigger> ();
JobDetail jobDetail = newJob (TestJob.class)
    .withIdentity(Constants.TEST_JOB_PREFIX, onstants.TEST_JOB_GRUOP_PREFIX)
    .build();

Trigger trigger = null;
int triggerIndex = 1;

for (Date date : dates) {
    trigger = newTrigger ()
       .withIdentity(Constants.SIMPLE_TRIGGER_PREFIX + triggerIndex, Constants.SIMPLE_TRIGGER_GROUP_PREFIX)
       .startAt(date)
       .withSchedule(simpleSchedule().withRepeatCount(0))
       .build();

   triggers.add(trigger);
}
jobAndTriggers.put(jobDetail, triggers);

sched.scheduleJobs (jobAndTriggers, true);

Now, when the program runs, say when I pass a list of date times like:
2013-03-13 12:21:33 |
2013-03-13 12:21:37 |
2013-03-13 12:22:41 |
2013-03-13 12:22:45 |
2013-03-13 12:23:49 |
The job will be only fired once which is the the last time stamp, I'm not sure what I did wrong, any help is appreciated. Following are some of the program logs:
12:19:33.265 [main] INFO  org.quartz.impl.StdSchedulerFactory - Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties'
12:19:33.265 [main] INFO  org.quartz.impl.StdSchedulerFactory - Quartz scheduler version: 2.1.7
12:19:33.265 [main] INFO  org.quartz.core.QuartzScheduler - Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.
12:19:33.265 [DefaultQuartzScheduler_QuartzSchedulerThread] DEBUG o.quartz.core.QuartzSchedulerThread - batch acquisition of 0 triggers
12:19:33.265 [main] DEBUG c.s.r.s.s.TriggerAndJobBuilder - Triggers created:
12:19:33.265 [main] DEBUG c.s.r.s.s.TriggerAndJobBuilder - SIMPLE_TRIGGER_GROUP.SIMPLE_TRIGGER1 which will fire job at 2013-03-13 12:21:33
12:19:33.265 [main] DEBUG c.s.r.s.s.TriggerAndJobBuilder - SIMPLE_TRIGGER_GROUP.SIMPLE_TRIGGER1 which will fire job at 2013-03-13 12:21:37
12:19:33.265 [main] DEBUG c.s.r.s.s.TriggerAndJobBuilder - SIMPLE_TRIGGER_GROUP.SIMPLE_TRIGGER1 which will fire job at 2013-03-13 12:22:41
12:19:33.265 [main] DEBUG c.s.r.s.s.TriggerAndJobBuilder - SIMPLE_TRIGGER_GROUP.SIMPLE_TRIGGER1 which will fire job at 2013-03-13 12:22:45
12:19:33.265 [main] DEBUG c.s.r.s.s.TriggerAndJobBuilder - SIMPLE_TRIGGER_GROUP.SIMPLE_TRIGGER1 which will fire job at 2013-03-13 12:23:49
12:19:33.265 [DefaultQuartzScheduler_QuartzSchedulerThread] DEBUG o.quartz.core.QuartzSchedulerThread - batch acquisition of 1 triggers
12:19:34.109 [Timer-0] DEBUG org.quartz.utils.UpdateChecker - Checking for available updated version of Quartz...
12:19:34.265 [Timer-1] DEBUG org.quartz.utils.UpdateChecker - Checking for available updated version of Quartz...
12:19:49.265 [DefaultQuartzScheduler_QuartzSchedulerThread] DEBUG o.q.simpl.PropertySettingJobFactory - Producing instance of Job 'TEST_GROUP.TEST_PING_JOB', class=com.test.TestJob
12:19:49.265 [DefaultQuartzScheduler_QuartzSchedulerThread] DEBUG o.quartz.core.QuartzSchedulerThread - batch acquisition of 0 triggers
12:23:49.265 [DefaultQuartzScheduler_Worker-1] DEBUG org.quartz.core.JobRunShell - Calling execute on job TEST_GROUP.TEST_PING_JOB
12:23:49.265 [DefaultQuartzScheduler_Worker-1] INFO  c.s.r.s.s.TestJob - Entered TestJob execute method at 2013-03-13 12:23:49

A: Perhaps you have been assigning the same identifier for all the triggers so its the last one that is actually being considered.
triggerIndex = 1;
`Constants.SIMPLE_TRIGGER_PREFIX + triggerIndex`

Change this to something unique and there will be different triggers for each date you are sending in the list.


text:
Q: Why to use PortletURL? This thread is not a question , it was a doubt raised when I was going through Liferay Forums about using PortletURL.
In some cases I see this PortletURL inside the javscript Method
function createRowURL() {
   var portletURL = new Liferay.PortletURL();
   portletURL.setParameter("rowNumber", "25" );
   return portletURL.toString();
}

In some cases I see this PortletURL inside the doView Method as shown
To get currentURL :
PortletURL url = PortletURLUtil.getCurrent(renderRequest, mimeResponse or renderResponse)

creating PortletURL from renderResponse :

*

*For RenderURL:
PortletURL renderURL = renderResponse.createRenderURL();

*For actionURL:
PortletURL actionURL = renderResponse.createActionURL();

Could anybody please tell me in which  case PortletURL would be useful ?

A: Portlet applications are different from normal web applications. Portlets are mini pages inside a parent page called a portal and multiple portals become a book (a Weblogic term). Normal URL will not work in this situation. Aside from the reason given above, a portlet has a life circle with different states. You have to give the Portlet container a way to determine which portlet is communicating with it and what state it is being in - such as the window state of the portlet - is it minimized, maximized, or normal. Of course, another important function of the PortletUrl is to carry request parameters. If you are looking at a PortletURL you will sure see a lot exotic names along with the request parameters you give it.
Although most of the information needed by a PortletURL are common in many situations, the structure of a PortletURL is implementation-dependent and it is generated by the Portlet container one way or the other. There has been some time since my last liferay experience. I never used liferay specific javascript in my application. I used my own javascript/ajax to communication with the portal container. So I am just guessing the javascript way you presented is also liferay specific and won't be portable among different portal frameworks.
Edit: added types of PortletURLs and their differences and usage following comment from @PrakashK.
There are two types of PortletURLs:

*

*Action URLs, they trigger an action request followed by a render request.

*Render URLs, they trigger a render request.

So the purpose of an ActionURL is to trigger some kind of action - such as pressing a button. The action request will be intercepted by portlet container and send to appropriate action request handlers which process the action request and set necessary render parameters to be used by the render phase. In the life cycle of a portlet, a render request ALWAYS follows an action request. On the other hand, a RenderURl, as it's name suggested, is mainly for rendering the portlet.
Because of the "rendering" nature of a RenderURL, in JSR168(Portlet 1.0), you could not serve dynamically generated resources directly through the portlet. The only workaround is to use an additional servlet to serve the resources. The biggest problem of this approach is the inability of a Servlet to be involved in the lifecycle of a portlet. Direct links to the resources in the same portlet web application  are not guaranteed to pass through the portal server and will not have portlet context available. To overcome this, in JSR286(Portlet 2.0), a feature called resource serving and a new kind of URL called ResourceURL has been introduced to enable a portlet to dynamically serve a resource. ResourceURL is not a PortletURL although they extend the same BaseURL. The biggest difference between a ResourceURL and an ActionURL is that a ResourceURL will NOT trigger a render request. This makes possible an Ajax request to the resource.
For more information on Portlet 2.0, please refer to  [JSR286].
Hope the above information would be useful to you.


text:
Q: How to set border between two products in css? Here is my html code:

Our Products

                   Buy

Express

                         $.79.00

                   Buy

Full

                         $.79.00

And here is my jsfiddle: http://jsfiddle.net/brs0kr6q/
Now my page look like this http://s3.postimg.org/9akuidnf7/Untitled_2.png
I need add border around each product like this http://s30.postimg.org/424hmkpoh/products.jpg
For that, when i add border, something not aligned properly. I think in my existing css code will be override the styles.
Can anyone help me to fix this?

A: On your link image: add a class (eg: bordered)

And CSS:
a.bordered {
text-decoration: none;
display: block;
border: solid 1px #dddddd;
}

A: Consider this following CSS:
.grid-item a{
   border: 1px solid #dddddd;
   display: block;
}

Updated DEMO

A: try the following:
.grid-item {
    border:solid;
    padding-left:0;
}

.product {
    padding-left: 40px;
    padding-bottom: 10px;
}

the result you see in the fiddle:
http://jsfiddle.net/brs0kr6q/2/
if you want exactly the same as the picture you posted you need to update the class .coll-prod-caption remove the margin from there
EDIT:
Working with selectors:
http://jsfiddle.net/brs0kr6q/5/
you write product instead of first, i have do that only for you that you get a feeling how selectors will work

A: The selector you need is ".product > .grid-item", so the border is applied to .grid-items that are child of .product but not to others .grid-items.
.product > .grid-item {border:1px solid #ddd... }

Check this: http://www.w3.org/TR/CSS21/selector.html#pattern-matching
...change border, padding, margin, etc as needed, with selectors with more specificity http://www.w3.org/TR/CSS2/cascade.html#specificity . I guess something like:
.product > .grid-item {
 border: 1px solid #ddd;
 margin-left: 40px;
 padding-left: 0;
}
.product > .grid-item > .coll-prod-caption {margin-bottom:0}

...produce your wanted results.

A: Ok, Inside your CSS file Add this: border: 1px solid #d5d5d5;
margin-right: 5px; in the .product { ... and from .grid-item { remove padding-left: 40px; the last and final stye: remove margin-bottom: 30px; from .coll-prod-caption {... That should give you the exact result!


text:
Q: Sort array of objects based on another array I have a array of makes as follows:
const makes = [
{id: "4", name: "Audi"},
{id: "5", name: "Bmw"},
{id: "6", name: "Porsche"},
{id: "31", name: "Seat"},
{id: "32", name: "Skoda"},
{id: "36", name: "Toyota"},
{id: "38", name: "Volkswagen"}
]

And I want to sort that array based on another array:
const preferred_makes = ['Volkswagen', 'Audi'];

What I do now is as follows:
const preferred_makes = ['Volkswagen', 'Audi'];

const makes = [
{id: "4", name: "Audi"},
{id: "5", name: "Bmw"},
{id: "6", name: "Porsche"},
{id: "31", name: "Seat"},
{id: "32", name: "Skoda"},
{id: "36", name: "Toyota"},
{id: "38", name: "Volkswagen"}
]

const mainMakes = []
const otherMakes = []

makes.map(make => _.includes(preferred_makes, make.name) ? mainMakes.push(make) : otherMakes.push(make))

console.log(mainMakes)
console.log(otherMakes)

But is there any better way? Can I sort makes to show those preferred_makes as first elements of the array?
Here is the fiddle.

A: You could take an object with the by one incremented indices and take a default value of Infinity for not found names. Then sort by the delta of the values.

var preferred_makes = ['Volkswagen', 'Audi'],
    preferred = preferred_makes.reduce((o, k, i) => (o[k] = i + 1, o), {});
    array = [{ id: "4", name: "Audi" }, { id: "5", name: "Bmw" }, { id: "6", name: "Porsche" }, { id: "31", name: "Seat" }, { id: "32", name: "Skoda" }, { id: "36", name: "Toyota" }, { id: "38", name: "Volkswagen" }];

array.sort((a, b) => (preferred[a.name] || Infinity) - (preferred[b.name] || Infinity));

console.log(array);
.as-console-wrapper { max-height: 100% !important; top: 0; }

A: A regular array.sort() with a custom comparison function should be able to do this.

const preferred_makes = ['Volkswagen', 'Audi'];

const makes = [
  {id: "4", name: "Audi"},
  {id: "5", name: "Bmw"},
  {id: "6", name: "Porsche"},
  {id: "31", name: "Seat"},
  {id: "32", name: "Skoda"},
  {id: "36", name: "Toyota"},
  {id: "38", name: "Volkswagen"}
]

const sorted = makes.slice().sort((a, b) => {
  // Convert true and false to 1 and 0
  const aPreferred = new Number(preferred_makes.includes(a.name))
  const bPreferred = new Number(preferred_makes.includes(b.name))

  // Return 1, 0, or -1
  return bPreferred - aPreferred
})

console.log(sorted)

A: You could use reduce to make two arrays without the requirement for sorting:

const preferred_makes = ['Volkswagen','Audi'];
const makes = [{id:"4",name:"Audi"},{id:"5",name:"Bmw"},{id:"6",name:"Porsche"},{id:"31",name:"Seat"},{id:"32",name:"Skoda"},{id:"36",name:"Toyota"},{id:"38",name:"Volkswagen"}];

const [mainMakes, otherMakes] = makes.reduce(([a, b], { id, name }) => ((preferred_makes.includes(name) ? a : b).push({ id, name }), [a, b]), [[], []]);

console.log(mainMakes);
console.log(otherMakes);
.as-console-wrapper { max-height: 100% !important; top: auto; }

To make it even faster, you could Set.prototype.has instead of includes:

const preferred_makes = new Set(['Volkswagen','Audi']);
const makes = [{id:"4",name:"Audi"},{id:"5",name:"Bmw"},{id:"6",name:"Porsche"},{id:"31",name:"Seat"},{id:"32",name:"Skoda"},{id:"36",name:"Toyota"},{id:"38",name:"Volkswagen"}];

const [mainMakes, otherMakes] = makes.reduce(([a, b], { id, name }) => ((preferred_makes.has(name) ? a : b).push({ id, name }), [a, b]), [[], []]);

console.log(mainMakes);
console.log(otherMakes);
.as-console-wrapper { max-height: 100% !important; top: auto; }

A: You can also sort by the Array.indexOf if the index is there otherwise use String.localeCompare. No real need for lodash really:

const makes = [ {id: "4", name: "Audi"}, {id: "6", name: "Porsche"}, {id: "31", name: "Seat"}, {id: "32", name: "Skoda"}, {id: "5", name: "Bmw"}, {id: "36", name: "Toyota"}, {id: "38", name: "Volkswagen"} ]
const list = ['Volkswagen', 'Audi'];

let result = makes.sort((a,b) => {
  let i = list.indexOf(a.name)
  return i < 0 ? a.name.localeCompare(b.name) : list.indexOf(b.name) - i
})

console.log(result)

A: With lodash you can generate a dictionary of the original index by the car's make (indexByMake) using _.invert() to get an object of { [car make]: original array index }, and map the values back to numbers.
Use _.orderBy() to sort the array, and use the values from indexByMake according to the name:

const preferred_makes = ['Volkswagen', 'Audi'];
const array = [{ id: "4", name: "Audi" }, { id: "5", name: "Bmw" }, { id: "6", name: "Porsche" }, { id: "31", name: "Seat" }, { id: "32", name: "Skoda" }, { id: "36", name: "Toyota" }, { id: "38", name: "Volkswagen" }];

const indexByMake = _.mapValues(_.invert(preferred_makes), Number);

const result = _.sortBy(array, ({ name }) => indexByMake[name]);

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>


text:
Q: When exactly do calendars repeat themselves (Gregorian)? After how many years exactly do we get the same calendar as the current year?
When can I safely reuse my calendar again for the present year?

A: According to this link
http://www.timeanddate.com/calendar/repeating.html - there is no definitive answer (2016's calendar matches every +/-28 years for some time, where 2015's does not match years as periodically (+6,+6, +11, ...).
On a further note: due to the calculation of holidays (e.g. Easter is the first Sunday after the first full moon in Spring [ https://en.wikipedia.org/wiki/Easter#Computations ] ) holidays will not easily repeat periodically either.

A: The Gregorian calendar has a period of 400 years (146,097 days).


text:
Q: Having an instanced, derived class put a pointer to itself into an array? Okay so here's a real mess of a question - I don't even entirely know what to search for.
I asked a question here, related to a game's entity handling system: Initiating a derived class with specific variable values
So far, that's working out great for me, but for one thing. I want to have mobs not just collide with eachother, but interact.
How can I look up a specific instance of the derived class, by coordinates?
For example, find the baseObject:Enemy() located at 22,22 and get the value of "nType" from within it
What comes to mind is putting some kind of pointer to an instance in an array, and moving it when said entity moves... but how do I make a derived class add a pointer to itself to an array? and how do I then pull something from that instance's variables?
Whew. Hope this makes sense.

A: Well, I think a solution to this problem is to use delegates/event passing.
Let's say you have a mob, as someone said earlier you could have a "mob watcher" object. The idea is that when a GameEntity is part of a mob, that entity subscribes to the "mob watcher". If that entity leaves the mob, it will let the "mob watcher" know about it (unsubscribe).
So, when you need to know, who's composing a mob, you could just ask the mob watcher for the "mob list", if you need to search by Entity position you could then work yourself through the list of entities composing the mob, and find the one in the "position of interest".
If your mobs are gigantic you could add some kind of spatial hash feature to your mob watcher, so you could easily filter and ask for "guys in the mob which are located in gameGrid[10][13]".
If you use event passing, it's quite cool because if when you want to forward messages between the mob, sending an event to the mob watcher could be used to then forward the aforementioned event to the subscribed entities.
If you use delegates, it works in a similar way.
Observer Pattern
Delegate Pattern

A: Well, the specific question you're asking is easy to answer: the pseudo-variable this is available in all member functions; it points to the current object.
The "looking up by coordinates" part is trickier; you might consider using an octree structure to organize your objects (Google is your friend there.)

A: You will need to make a new object whose job is to keep track of where the "mobs" are. According to your question, this new object will need to contain at least a std::vector which contains a pointer to each "mob" in the world, and also a member function like:
mob* findEnemy( int x, int y );

Unfortunately, what you asked for in your question is probably not what you want. You probably want to get all of the "mobs" near a point:
std::vector<mob*> findEnemiesNearPoint( int x, int y );

...but returning a std::vector can be very slow, so you probably want an array instead, but the array must be sized carefully, and now we're far far beyond the amount of information provided in your question so far.


text:
Q: Returning viewbag asp.net mvc by ajax evokes memory leak Dealing up with asp.net MVC I faced with a problem of memory leak on server part.
I`m trying to refresh dataset from database using ajax query to my controller. Everything is working fine, but the memory usage growing proportionally to the queries count. So I need some help to clear memory after each of ajax query.
Controller:
    [HttpPost]
    public ActionResult Index(string incData)
    {
        DbEntities od = new DbEntities();
        IEnumerable<TestProc_Result> result = od.TestProc(incData);

        ViewBag.Proc_Result = result;
        return View();
    }

View:

        <input id="textField" name="textField" type="text" />

    @if(ViewBag.TestProc_Result != null)
    {

                Email
                Name
                Surname
                Phone

        @foreach (var item in ViewBag.TestProc_Result)
        {

                    @item.Email;

                    @item.SenderName;

                    @item.SenderSurname;

                    @item.Phone;

        }

    }

jQuery/ajax:
$("#textField").keypress(function (event) {

    var st = $("input[name='textField']").val() + event.key;
    var ser = { 'incData': st };
    $.ajax({
        url: '/Home/Index',
        type: "POST",
        cache: false,
        dataType: "html",
        data: ser,
        success: function (data) {
            $("#con").empty().append($(data).find('#con'));
        }
    });
});


text:
Q: Delete file from path value stored in array method fails if file is not present I have a dynamically generated array of file paths which may look like this:
paths = ["/lib/my_folder/foo", "/lib/my_folder/bar", "/lib/my_folder/baz", ...]

So I want to do:
for path in paths do |path|
  File.delete(path) #if file exists
end

This is failing as sometimes the element in the array points to a file that is no longer there.
I tried:
for path in paths
  if !path.blank?
    File.delete(path)
  end
end

but still fails with a No such file or directory... error msg.
How can I go about writing a loop to dele the element(s) left in the array without it failing?

A: paths.each { |path| File.delete(path) if File.exists?(path) }


text:
Q: How to receive quota alert in GAE Is there a way to get alerted when I am nearing a quota in GAE? I could not find it online or in the administration console.

A: You might like to try it Google Cloud Monitoring. It doesn't specifically allow you to set alerts on quotas, but you can set other alerts that might help. For example an alert on the rate of 500 will fire if you get errors due to quotas, as well as catching other problems.