text:
Q: Model selection - GLM and ANOVA I know this is quite a basic question and I've checked some related posts on stackoverflow after looking for tutorials/articles explaining what I'm looking for, but so far I did not really get all my points answered.
I did field measurements of different ecological response variables and now have to identify the factors which have a significant influence. For example, I measured bait consumption by soil fauna. I did this on a total of 24 plots (2 regions * 2 elevation levels * 2 expositions (North/South) * 3 plot replicates). Apart from these factors (region/elevation/exposition), I measured some soil properties and extracted climate data from an already existing grid.
To reduce the complexity of my soil and climate data, I've done a co-inertia analysis, telling me that soil & climate data do not seem to be significantly correlated.
I thus did each a PCA for my soil and my climate data & extracted the first 2 dimensions.
Now, as the residuals of my bait consumption data are not normally distributed, I'm doing a GLM (for other analysis where ND is not violated, I'll do ANOVAs). However, I get myself kind of lost in the process of comparing different GLMs and choosing the most appropriate one.
I started off as follows:
baits.glm0 <- glm(consumption ~ 1, data = baits.stick.means,
              family = poisson)
baits.glm1 <- glm(consumption ~ region + exposition +
                  elevation_level, data = baits.stick.means,
                  family = poisson)
anova(baits.glm0, baits.glm1, test = "Chisq")

This tells me that including above factors indeed helps in explaining consumption, right. But: how do I continue in adding the other factors (climate_pca1/climate_pca2, soil_pca1/soil_pca2)? I mean there are many different possibilities which factors I add first, which I leave out, do I allow for interactions between e.g. region and exposition, etc ... I can't simply construct different models and look at their AIC, since I get "Inf" for latter, due to the number of factor levels I assume.
So, how would the correct procedure/comparison method be in this case?
Data subset in case it is helpful:
structure(list(stick_number = c(219L, 284L, 62L, 254L, 233L,
187L, 157L, 339L, 57L, 39L, 347L, 340L, 77L, 191L, 321L, 218L,
82L, 153L, 334L, 230L, 194L, 358L, 336L, 78L, 121L, 210L, 224L,
322L, 239L, 83L, 344L, 117L, 204L, 182L, 236L, 306L, 42L, 5L,
112L, 92L, 225L, 32L, 50L, 328L, 359L, 151L, 71L, 30L, 162L,
13L, 111L, 104L, 206L, 296L, 173L, 283L, 228L, 293L, 86L, 256L,
186L, 241L, 264L, 222L, 287L, 143L, 342L, 158L, 266L, 68L, 118L,
156L, 277L, 12L, 8L, 281L, 172L, 259L, 127L, 267L, 6L, 81L, 341L,
327L, 51L, 53L, 31L, 60L, 89L, 308L, 352L, 134L, 64L, 310L, 67L,
302L, 74L, 141L, 268L, 276L), plot_id = c("VSH3", "TSH1", "VNM2",
"VNH2", "VNH1", "VSH1", "TNM2", "TNH2", "VNM1", "VSM3", "TNH3",
"TNH2", "VNM3", "VSH1", "TNH1", "VSH3", "VNM3", "TNM2", "TNH2",
"VNH1", "VSH1", "TNH3", "TNH2", "VNM3", "TSM3", "VSH2", "VSH3",
"TNH1", "VNH1", "VNM3", "TNH2", "TSM2", "VSH2", "VSH1", "VNH1",
"TSH3", "VSM3", "VSM1", "TSM2", "TSM1", "VSH3", "VSM3", "VNM1",
"TNH1", "TNH3", "TNM2", "VNM2", "VSM2", "TNM2", "VSM1", "TSM2",
"TSM1", "VSH2", "TSH2", "TNM3", "TSH1", "VNH1", "TSH2", "VNM3",
"VNH3", "VSH1", "VNH2", "VNH3", "VSH3", "TSH2", "TNM1", "TNH2",
"TNM2", "VNH3", "VNM2", "TSM2", "TNM2", "TSH1", "VSM1", "VSM1",
"TSH1", "TNM3", "VNH3", "TSM3", "VNH3", "VSM1", "VNM3", "TNH2",
"TNH1", "VNM1", "VNM1", "VSM3", "VNM1", "VNM3", "TSH3", "TNH3",
"TSM3", "VNM2", "TSH3", "VNM2", "TSH3", "VNM2", "TNM1", "VNH3",
"TSH1"), site = c("VSH", "TSH", "VNM", "VNH", "VNH", "VSH", "TNM",
"TNH", "VNM", "VSM", "TNH", "TNH", "VNM", "VSH", "TNH", "VSH",
"VNM", "TNM", "TNH", "VNH", "VSH", "TNH", "TNH", "VNM", "TSM",
"VSH", "VSH", "TNH", "VNH", "VNM", "TNH", "TSM", "VSH", "VSH",
"VNH", "TSH", "VSM", "VSM", "TSM", "TSM", "VSH", "VSM", "VNM",
"TNH", "TNH", "TNM", "VNM", "VSM", "TNM", "VSM", "TSM", "TSM",
"VSH", "TSH", "TNM", "TSH", "VNH", "TSH", "VNM", "VNH", "VSH",
"VNH", "VNH", "VSH", "TSH", "TNM", "TNH", "TNM", "VNH", "VNM",
"TSM", "TNM", "TSH", "VSM", "VSM", "TSH", "TNM", "VNH", "TSM",
"VNH", "VSM", "VNM", "TNH", "TNH", "VNM", "VNM", "VSM", "VNM",
"VNM", "TSH", "TNH", "TSM", "VNM", "TSH", "VNM", "TSH", "VNM",
"TNM", "VNH", "TSH"), region = c("valais", "ticino", "valais",
"valais", "valais", "valais", "ticino", "ticino", "valais", "valais",
"ticino", "ticino", "valais", "valais", "ticino", "valais", "valais",
"ticino", "ticino", "valais", "valais", "ticino", "ticino", "valais",
"ticino", "valais", "valais", "ticino", "valais", "valais", "ticino",
"ticino", "valais", "valais", "valais", "ticino", "valais", "valais",
"ticino", "ticino", "valais", "valais", "valais", "ticino", "ticino",
"ticino", "valais", "valais", "ticino", "valais", "ticino", "ticino",
"valais", "ticino", "ticino", "ticino", "valais", "ticino", "valais",
"valais", "valais", "valais", "valais", "valais", "ticino", "ticino",
"ticino", "ticino", "valais", "valais", "ticino", "ticino", "ticino",
"valais", "valais", "ticino", "ticino", "valais", "ticino", "valais",
"valais", "valais", "ticino", "ticino", "valais", "valais", "valais",
"valais", "valais", "ticino", "ticino", "ticino", "valais", "ticino",
"valais", "ticino", "valais", "ticino", "valais", "ticino"),
    exposition = c("south", "south", "north", "north", "north",
    "south", "north", "north", "north", "south", "north", "north",
    "north", "south", "north", "south", "north", "north", "north",
    "north", "south", "north", "north", "north", "south", "south",
    "south", "north", "north", "north", "north", "south", "south",
    "south", "north", "south", "south", "south", "south", "south",
    "south", "south", "north", "north", "north", "north", "north",
    "south", "north", "south", "south", "south", "south", "south",
    "north", "south", "north", "south", "north", "north", "south",
    "north", "north", "south", "south", "north", "north", "north",
    "north", "north", "south", "north", "south", "south", "south",
    "south", "north", "north", "south", "north", "south", "north",
    "north", "north", "north", "north", "south", "north", "north",
    "south", "north", "south", "north", "south", "north", "south",
    "north", "north", "north", "south"), elevation_level = c("high",
    "high", "mid", "high", "high", "high", "mid", "high", "mid",
    "mid", "high", "high", "mid", "high", "high", "high", "mid",
    "mid", "high", "high", "high", "high", "high", "mid", "mid",
    "high", "high", "high", "high", "mid", "high", "mid", "high",
    "high", "high", "high", "mid", "mid", "mid", "mid", "high",
    "mid", "mid", "high", "high", "mid", "mid", "mid", "mid",
    "mid", "mid", "mid", "high", "high", "mid", "high", "high",
    "high", "mid", "high", "high", "high", "high", "high", "high",
    "mid", "high", "mid", "high", "mid", "mid", "mid", "high",
    "mid", "mid", "high", "mid", "high", "mid", "high", "mid",
    "mid", "high", "high", "mid", "mid", "mid", "mid", "mid",
    "high", "high", "mid", "mid", "high", "mid", "high", "mid",
    "mid", "high", "high"), climate_pca1 = c(-1.480220428, -1.828098745,
    1.770907449, -1.209471355, -1.262109584, -1.575038041, 1.10552354,
    -2.332118439, 1.922660686, 2.133086246, -2.251591285, -2.332118439,
    1.843690586, -1.575038041, -2.593633876, -1.480220428, 1.843690586,
    1.10552354, -2.332118439, -1.262109584, -1.575038041, -2.251591285,
    -2.332118439, 1.843690586, 2.081946695, -1.354302896, -1.480220428,
    -2.593633876, -1.262109584, 1.843690586, -2.332118439, 1.88376908,
    -1.354302896, -1.575038041, -1.262109584, -2.026443343, 2.133086246,
    2.129010846, 1.88376908, 1.744163466, -1.480220428, 2.133086246,
    1.922660686, -2.593633876, -2.251591285, 1.10552354, 1.770907449,
    2.333468357, 1.10552354, 2.129010846, 1.88376908, 1.744163466,
    -1.354302896, -1.916565298, 1.208123392, -1.828098745, -1.262109584,
    -1.916565298, 1.843690586, -1.027990027, -1.575038041, -1.209471355,
    -1.027990027, -1.480220428, -1.916565298, 0.701232975, -2.332118439,
    1.10552354, -1.027990027, 1.770907449, 1.88376908, 1.10552354,
    -1.828098745, 2.129010846, 2.129010846, -1.828098745, 1.208123392,
    -1.027990027, 2.081946695, -1.027990027, 2.129010846, 1.843690586,
    -2.332118439, -2.593633876, 1.922660686, 1.922660686, 2.133086246,
    1.922660686, 1.843690586, -2.026443343, -2.251591285, 2.081946695,
    1.770907449, -2.026443343, 1.770907449, -2.026443343, 1.770907449,
    0.701232975, -1.027990027, -1.828098745), climate_pca2 = c(-1.923853312,
    -0.509591235, 0.295280113, 0.197102242, -0.42062989, -1.849214144,
    2.728812267, 1.351144076, -0.274402516, -1.379004788, 0.77931106,
    1.351144076, -0.273885517, -1.849214144, 2.40580586, -1.923853312,
    -0.273885517, 2.728812267, 1.351144076, -0.42062989, -1.849214144,
    0.77931106, 1.351144076, -0.273885517, -0.018829514, -1.687742087,
    -1.923853312, 2.40580586, -0.42062989, -0.273885517, 1.351144076,
    0.016797936, -1.687742087, -1.849214144, -0.42062989, -0.733165106,
    -1.379004788, -1.358442237, 0.016797936, 0.059349245, -1.923853312,
    -1.379004788, -0.274402516, 2.40580586, 0.77931106, 2.728812267,
    0.295280113, -1.376450585, 2.728812267, -1.358442237, 0.016797936,
    0.059349245, -1.687742087, -0.595492434, 2.621840242, -0.509591235,
    -0.42062989, -0.595492434, -0.273885517, -0.670404999, -1.849214144,
    0.197102242, -0.670404999, -1.923853312, -0.595492434, 2.615665322,
    1.351144076, 2.728812267, -0.670404999, 0.295280113, 0.016797936,
    2.728812267, -0.509591235, -1.358442237, -1.358442237, -0.509591235,
    2.621840242, -0.670404999, -0.018829514, -0.670404999, -1.358442237,
    -0.273885517, 1.351144076, 2.40580586, -0.274402516, -0.274402516,
    -1.379004788, -0.274402516, -0.273885517, -0.733165106, 0.77931106,
    -0.018829514, 0.295280113, -0.733165106, 0.295280113, -0.733165106,
    0.295280113, 2.615665322, -0.670404999, -0.509591235), soil_pca1 = c(-5.56767863419797,
    1.95393811095034, -0.260227094874325, -1.61085398656141,
    -1.66958542579672, -0.397280823855903, 3.7169854524207, 1.84352513299293,
    -0.6551280697025, -6.50320343705425, 2.00291533466174, 1.84352513299293,
    -0.620445610945974, -0.397280823855903, 2.42091640839051,
    -5.56767863419797, -0.620445610945974, 3.7169854524207, 1.84352513299293,
    -1.66958542579672, -0.397280823855903, 2.00291533466174,
    1.84352513299293, -0.620445610945974, 0.304033246117126,
    -0.84551981325722, -5.56767863419797, 2.42091640839051, -1.66958542579672,
    -0.620445610945974, 1.84352513299293, 0.859821441854325,
    -0.84551981325722, -0.397280823855903, -1.66958542579672,
    2.52191101044192, -6.50320343705425, -4.58332766496856, 0.859821441854325,
    1.81674404592665, -5.56767863419797, -6.50320343705425, -0.6551280697025,
    2.42091640839051, 2.00291533466174, 3.7169854524207, -0.260227094874325,
    -3.61912580538706, 3.7169854524207, -4.58332766496856, 0.859821441854325,
    1.81674404592665, -0.84551981325722, 2.72504002601633, 2.85277767098365,
    1.95393811095034, -1.66958542579672, 2.72504002601633, -0.620445610945974,
    -0.76015927833061, -0.397280823855903, -1.61085398656141,
    -0.76015927833061, -5.56767863419797, 2.72504002601633, 4.07392776417628,
    1.84352513299293, 3.7169854524207, -0.76015927833061, -0.260227094874325,
    0.859821441854325, 3.7169854524207, 1.95393811095034, -4.58332766496856,
    -4.58332766496856, 1.95393811095034, 2.85277767098365, -0.76015927833061,
    0.304033246117126, -0.76015927833061, -4.58332766496856,
    -0.620445610945974, 1.84352513299293, 2.42091640839051, -0.6551280697025,
    -0.6551280697025, -6.50320343705425, -0.6551280697025, -0.620445610945974,
    2.52191101044192, 2.00291533466174, 0.304033246117126, -0.260227094874325,
    2.52191101044192, -0.260227094874325, 2.52191101044192, -0.260227094874325,
    4.07392776417628, -0.76015927833061, 1.95393811095034), soil_pca2 = c(-1.20094768276013,
    -0.81049387016335, 2.4943393252285, 1.57423563197107, 1.44861597315028,
    2.2610844297929, -0.297648866553386, -2.38340996245776, 2.40878156685994,
    -2.3823643056849, -2.6231255135526, -2.38340996245776, 2.23860580682454,
    2.2610844297929, -1.9422384338934, -1.20094768276013, 2.23860580682454,
    -0.297648866553386, -2.38340996245776, 1.44861597315028,
    2.2610844297929, -2.6231255135526, -2.38340996245776, 2.23860580682454,
    -0.828230153957865, 1.8842217721005, -1.20094768276013, -1.9422384338934,
    1.44861597315028, 2.23860580682454, -2.38340996245776, 1.69610095222163,
    1.8842217721005, 2.2610844297929, 1.44861597315028, 0.219212508989128,
    -2.3823643056849, -0.56282968564021, 1.69610095222163, -0.404846537234961,
    -1.20094768276013, -2.3823643056849, 2.40878156685994, -1.9422384338934,
    -2.6231255135526, -0.297648866553386, 2.4943393252285, -2.50519920681956,
    -0.297648866553386, -0.56282968564021, 1.69610095222163,
    -0.404846537234961, 1.8842217721005, -0.561939092870071,
    -1.23645258422661, -0.81049387016335, 1.44861597315028, -0.561939092870071,
    2.23860580682454, 1.62581106228919, 2.2610844297929, 1.57423563197107,
    1.62581106228919, -1.20094768276013, -0.561939092870071,
    -0.111283133612885, -2.38340996245776, -0.297648866553386,
    1.62581106228919, 2.4943393252285, 1.69610095222163, -0.297648866553386,
    -0.81049387016335, -0.56282968564021, -0.56282968564021,
    -0.81049387016335, -1.23645258422661, 1.62581106228919, -0.828230153957865,
    1.62581106228919, -0.56282968564021, 2.23860580682454, -2.38340996245776,
    -1.9422384338934, 2.40878156685994, 2.40878156685994, -2.3823643056849,
    2.40878156685994, 2.23860580682454, 0.219212508989128, -2.6231255135526,
    -0.828230153957865, 2.4943393252285, 0.219212508989128, 2.4943393252285,
    0.219212508989128, 2.4943393252285, -0.111283133612885, 1.62581106228919,
    -0.81049387016335), exposure_days = c(21, 19, 20, 20, 20,
    21, 20, 20, 20, 19, 20, 20, 20, 21, 20, 21, 20, 20, 20, 20,
    21, 20, 20, 20, 19, 21, 21, 20, 20, 20, 20, 19, 21, 21, 20,
    19, 19, 19, 19, 19, 21, 19, 20, 20, 20, 20, 20, 19, 20, 19,
    19, 19, 21, 19, 20, 19, 20, 19, 20, 20, 21, 20, 20, 21, 19,
    20, 20, 20, 20, 20, 19, 20, 19, 19, 19, 19, 20, 20, 19, 20,
    19, 20, 20, 20, 20, 20, 19, 20, 20, 19, 20, 19, 20, 19, 20,
    19, 20, 20, 20, 19), consumption = c(0.065625, 0, 0.3125,
    0.34375, 0.175, 0.184375, 0.453125, 0.0192307692307692, 0.271875,
    0, 0.00625, 0, 0.896875, 0.25625, 0.3125, 0.021875, 0.265625,
    0.46875, 0.0375, 0.421875, 0.121875, 0.159375, 0.181818181818182,
    0.1875, 0.09375, 0.0625, 0.096875, 0.583333333333333, 0.0625,
    0.140625, 0.1875, 0, 0.00625, 0.5875, 0.1625, 0.5625, 0.078125,
    0, 0, 0, 0.015625, 0, 0.490625, 0.533333333333333, 0.246875,
    0.546875, 0.3125, 0.209375, 0.225, 0, 0, 0.375, 0.08125,
    0.265625, 0.178125, 0.2, 0.1, 0.109375, 0.590625, 0.065625,
    0.0375, 0.1375, 0.115625, 0.13125, 0.53125, 0.4375, 0.21875,
    0.171875, 0.06875, 0.1875, 0.0625, 0.65625, 0, 0, 0.00625,
    0, 0.225, 0.153125, 0.171875, 0.10625, 0, 0.596875, 0.125,
    0.190909090909091, 0.496875, 0.88125, 0.00625, 0.615625,
    0.725, 0.5625, 0.146875, 0.046875, 0.31875, 0.1, 0.646875,
    0.265625, 0.578125, 0.5, 0.075, 0.03125), cons_transf = c(0.25617376914899,
    0, 0.559016994374947, 0.586301969977929, 0.418330013267038,
    0.429389100932942, 0.673145600891813, 0.138675049056307,
    0.521416340365355, 0, 0.0790569415042095, 0, 0.947034846243791,
    0.506211418282915, 0.559016994374947, 0.14790199457749, 0.515388203202208,
    0.684653196881458, 0.193649167310371, 0.649519052838329,
    0.349106001094224, 0.399217985566783, 0.426401432711221,
    0.433012701892219, 0.306186217847897, 0.25, 0.311247489949718,
    0.763762615825973, 0.25, 0.375, 0.433012701892219, 0, 0.0790569415042095,
    0.766485485837795, 0.403112887414928, 0.75, 0.279508497187474,
    0, 0, 0, 0.125, 0, 0.700446286306095, 0.730296743340221,
    0.496865172858795, 0.739509972887452, 0.559016994374947,
    0.457575130443078, 0.474341649025257, 0, 0, 0.612372435695794,
    0.285043856274785, 0.515388203202208, 0.422048575403353,
    0.447213595499958, 0.316227766016838, 0.330718913883074,
    0.76852130744697, 0.25617376914899, 0.193649167310371, 0.370809924354783,
    0.340036762718386, 0.362284418654736, 0.728868986855663,
    0.661437827766148, 0.467707173346743, 0.414578098794425,
    0.262202212042538, 0.433012701892219, 0.25, 0.810092587300983,
    0, 0, 0.0790569415042095, 0, 0.474341649025257, 0.391311896062463,
    0.414578098794425, 0.325960120260132, 0, 0.772576857018122,
    0.353553390593274, 0.436931448752651, 0.704893608993584,
    0.938749167775929, 0.0790569415042095, 0.784617741323761,
    0.85146931829632, 0.75, 0.383242742918897, 0.21650635094611,
    0.564579489531811, 0.316227766016838, 0.804285397107271,
    0.515388203202208, 0.760345316287277, 0.707106781186548,
    0.273861278752583, 0.176776695296637), cons_transf2 = c(0.0635614814897446,
    0, 0.271933715483642, 0.295464212893836, 0.161268147596122,
    0.169215209288654, 0.373716409793584, 0.0190481949706944,
    0.240492189648823, 0, 0.00623054975063616, 0, 0.640207795265726,
    0.228131092825249, 0.271933715483642, 0.0216391751034812,
    0.235566071312767, 0.384411698910332, 0.0368139731227164,
    0.351976423157178, 0.115001392694507, 0.147881066813663,
    0.167054084663166, 0.171850256926659, 0.0896121586896871,
    0.0606246218164348, 0.0924652276720936, 0.45953232937844,
    0.0606246218164348, 0.131576357788719, 0.171850256926659,
    0, 0.00623054975063616, 0.46216045178471, 0.150572858479374,
    0.44628710262842, 0.0752234212375875, 0, 0, 0, 0.0155041865359653,
    0, 0.399195495094569, 0.42744401482694, 0.220640421096091,
    0.436236766774918, 0.271933715483642, 0.19010369723601, 0.20294084399669,
    0, 0, 0.318453731118535, 0.0781177792639521, 0.235566071312767,
    0.163924191654239, 0.182321556793955, 0.0953101798043249,
    0.103796793681644, 0.46412702075675, 0.0635614814897446,
    0.0368139731227164, 0.128832871842968, 0.109414785985867,
    0.123323216031999, 0.4260843953109, 0.362905493689368, 0.19782574332992,
    0.158605030176639, 0.066489741268833, 0.171850256926659,
    0.0606246218164348, 0.504556010752395, 0, 0, 0.00623054975063616,
    0, 0.20294084399669, 0.142475648246755, 0.158605030176639,
    0.100975917340002, 0, 0.468048594409932, 0.117783035656383,
    0.174716957408735, 0.403379601617143, 0.631936449515049,
    0.00623054975063616, 0.479721878714657, 0.545227050483323,
    0.44628710262842, 0.137040852260798, 0.0458095360312942,
    0.27668431824224, 0.0953101798043249, 0.49887955274759, 0.235566071312767,
    0.456237433481588, 0.405465108108164, 0.0723206615796261,
    0.0307716586667537), cons_transf3 = c(0.93841642228739, 1,
    0.761904761904762, 0.744186046511628, 0.851063829787234,
    0.844327176781003, 0.688172043010753, 0.981132075471698,
    0.786240786240786, 1, 0.993788819875776, 1, 0.527182866556837,
    0.796019900497512, 0.761904761904762, 0.978593272171254,
    0.790123456790123, 0.680851063829787, 0.963855421686747,
    0.703296703296703, 0.891364902506964, 0.862533692722372,
    0.846153846153846, 0.842105263157895, 0.914285714285714,
    0.941176470588235, 0.911680911680912, 0.631578947368421,
    0.941176470588235, 0.876712328767123, 0.842105263157895,
    1, 0.993788819875776, 0.62992125984252, 0.860215053763441,
    0.64, 0.927536231884058, 1, 1, 1, 0.984615384615385, 1, 0.670859538784067,
    0.652173913043478, 0.802005012531328, 0.646464646464647,
    0.761904761904762, 0.82687338501292, 0.816326530612245, 1,
    1, 0.727272727272727, 0.92485549132948, 0.790123456790123,
    0.848806366047745, 0.833333333333333, 0.909090909090909,
    0.901408450704225, 0.628683693516699, 0.93841642228739, 0.963855421686747,
    0.879120879120879, 0.896358543417367, 0.883977900552486,
    0.653061224489796, 0.695652173913043, 0.82051282051282, 0.853333333333333,
    0.935672514619883, 0.842105263157895, 0.941176470588235,
    0.60377358490566, 1, 1, 0.993788819875776, 1, 0.816326530612245,
    0.867208672086721, 0.853333333333333, 0.903954802259887,
    1, 0.626223091976517, 0.888888888888889, 0.83969465648855,
    0.668058455114823, 0.53156146179402, 0.993788819875776, 0.618955512572534,
    0.579710144927536, 0.64, 0.871934604904632, 0.955223880597015,
    0.758293838862559, 0.909090909090909, 0.607210626185958,
    0.790123456790123, 0.633663366336634, 0.666666666666667,
    0.930232558139535, 0.96969696969697), cons_transf4 = c(0.403357161506136,
    0, 0.678604404148727, 0.700509832663847, 0.559344471040698,
    0.569159528740626, 0.768079206421462, 0.267916144918562,
    0.647823092234906, 0, 0.184201574932019, 0, 0.964370624177648,
    0.63516704638624, 0.678604404148727, 0.279672235520349, 0.642820397664559,
    0.776808126488465, 0.334716475041085, 0.75, 0.495798120670194,
    0.542175721312549, 0.566516334942705, 0.572357121276666,
    0.454280148208035, 0.39685026299205, 0.459272637503557, 0.835549655827431,
    0.39685026299205, 0.520020955762976, 0.572357121276666, 0,
    0.184201574932019, 0.837534341801117, 0.545696441530553,
    0.825481812223657, 0.427493986669174, 0, 0, 0, 0.25, 0, 0.788708566719032,
    0.810960266076453, 0.627324676023275, 0.817766577547147,
    0.678604404148727, 0.593801934515397, 0.60822019955734, 0,
    0, 0.721124785153704, 0.433119552670451, 0.642820397664559,
    0.562654278669283, 0.584803547642573, 0.464158883361278,
    0.478232795693097, 0.839016706561048, 0.403357161506136,
    0.334716475041085, 0.516140057728184, 0.487173790093664,
    0.508198178407427, 0.809902950319371, 0.759147242968916,
    0.602535566043808, 0.555995022642329, 0.409660635300323,
    0.572357121276666, 0.39685026299205, 0.869006661221612, 0,
    0, 0.184201574932019, 0, 0.60822019955734, 0.53499374028254,
    0.555995022642329, 0.473634118592955, 0, 0.841965822923538,
    0.5, 0.575805138911868, 0.792043526329418, 0.958737489687269,
    0.184201574932019, 0.850691478848779, 0.898350889571526,
    0.825481812223657, 0.527613573622537, 0.360562392576852,
    0.683098604023617, 0.464158883361278, 0.864848670999924,
    0.642820397664559, 0.833055462911488, 0.7937005259841, 0.421716332650875,
    0.314980262473718)), row.names = c(NA, -100L), class = "data.frame")

A: to check multiple models and find the best one by AIC criterion you can use stepAIC() function from MASS package.
This function adds and subtracts variables from the model until it finds an optimal solution (taking into account AIC). In each step the fuction refits the model with one variable omitted or added.
What you can do is to build your model on all variables and let the function find the 'best' one:
regression<-glm(dependent_variable ~ ., df, family = "poisson")
model.stepwise.regression<-stepAIC(regression, direction = "both")


text:
Q: Let $ABCD$ be a square with sidelength 1 and $AKL$ is an equilateral triangle where $K$ lies on BC and L lies on CD. What is the area for AKL? I tried to use the Pythagorean Theorem to find one side of $AKL$, but there isn't enough information. What am I missing?

A: Let $a$ be the sidelength of the triangle $AKL$. Then $K$ and $L$ are the intersection points between the circle $\omega$ centered in $A$ with radius $a$ and $BC$ and $CD$ respectively. Since both the circle $\omega$ and the square $ABCD$ are symmetric with respect to the line $AC$ then $|BK| = |DL|$.
Let $b = |BK|$. Then by applying the Pythagorean Theorem on $ABK$ we get
$$a^2 = 1 + b^2$$
and by applying it on $KCL$ we get
$$a^2 = 2(1-b)^2 = 2 - 4b + 2b^2$$
Subtracting the two equations and solving for $b$ we get
$$b = 2 \pm \sqrt{3}.$$
Note that $0 < b < 1$ so we have to discard the option $2+\sqrt{3}$. Then
$$b = 2 - \sqrt{3}.$$
Now
$$|AKL| = |ABCD| - |ABK| - |KCL| - |ALD| = 1 - \dfrac{b}{2} - \dfrac{(1-b)^2}{2} - \dfrac{b}{2} = \dfrac{1-b^2}{2}$$
$$ = \boxed{2\sqrt{3} - 3}$$

A: Put it on a cartesian plane $A = (0,0); B= (1,0); C=(1,1); D=(0,1)$ and $K = (1,k)$ and $L=(j, 1)$.
Then ... it all comes out in the wash.
$AK = \sqrt{k^2 + 1} = KL = \sqrt{(1-k)^2 + (1-j)^2} = AL = \sqrt{1 + j^2} ; 1>k > 0; 1>j> 0$
So $k^2 + 1 = k^2 + j^2 - 2(k+j) + 2 = 1+ j^2$
So $j = k$ and $k^2 - 4k + 1 = 0$ so $k = 2 \pm \frac{\sqrt{12}}{2}$ and (as $k < 1$) $k = 2 - \sqrt{3}$
So $AK = KL = AL = \sqrt{8 - 4\sqrt{3}}$
So area of triangle is $\frac 12 b*h = \frac 12 * AK * \frac {\sqrt{3}}2*AK = \frac {\sqrt{3}}4*AK^2 = \frac {\sqrt 3}4*(8 - 4\sqrt{3}) = 2\sqrt{3} - 3$.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Cloudkit is not sending push notifications Push notifications are not being sent (or received) to my app which is using CloudKit subscriptions, as there are a lot of ways this can go south, I'm going to list below what I've done, which may help others having the same issue, and (hopefully) will point out what I'm doing wrong :(
Specifically, I'm trying to get a silent notification on record insertion (both in the background in the foreground) and I am getting neither.
Project settings I enable CloudKit under capabilities, setup the record type in Dashboard.  I enable push notifications for the app under capabilities.  And I enable background modes "remote-notification".
Register for remote notifications on launch:
    // Register for push notification
    let settings = UIUserNotificationSettings(forTypes: [.Alert,.Badge,.Sound], categories: nil)
    application.registerUserNotificationSettings(settings)

    // Register for remote notification
    application.registerForRemoteNotifications()

Listen for push notification registration success (Succeeds) and create subscription:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    NSLog("Remote notifications registered - %@",deviceToken)
    createSubscriptions()
}

Create my subscription object, and setup it's notification info, and save it to the server:
private func createSubscriptions(user : CKRecord, completion: (NSError?) -> ()) {
        let messageSubscription = CKSubscription(recordType: "Messages", predicate: NSPredicate(format:"TRUEPREDICATE"), subscriptionID: "Messages", options: .FiresOnRecordCreation)
        let notificationInfo = CKNotificationInfo()
        notificationInfo.shouldSendContentAvailable = true
        notificationInfo.soundName = ""
        messageSubscription.notificationInfo = notificationInfo
        CKContainer.defaultContainer().publicCloudDatabase.saveSubscription(subscription) { (_, error) in
            if let error = error {
                if error.domain == "CKErrorDomain" && error.code == 15 {
                    NSLog("Already set, ignoring dupe")
                }
                else
                {
                    completion(error)
                    return
                }
            }
            completion(nil)
        }
}

I can see in CloudKit Dashboard that the subscription does get created successfully.
I then create some records ("Message") from a second device or the dashboard, see that they are added either in query or dashboard calls, but the method I have to get the notification is never called:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
    // Crickets.  Never called
}

I understand notifications don't work on simulator.  I've tried this in dev using a device, and in production using testflight and a number of devices.  Am I missing osmething obvious?

A: You seem to be doing everything right. Two things I can think of:

*

*Are you sure you are registering for remote notifications? I can't see the call to application.registerForRemoteNotifications() anywhere. I am assuming you forgot to paste it here.

*Have you tried to delete the subscription in the panel and recreate it? I have had issues where registering the same subscription multiple times with different notificationInfo would break it and it would stop firing.

A: This works ... and is a little different from your version... I don't try and register for specific notifications, I register for all... and then look at them more closely after I have received them.
func application(application: UIApplication, didFinishLaunchingWithOptions    launchOptions: [NSObject: AnyObject]?) -> Bool {

    application.registerForRemoteNotifications()
    return true
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    let notification = CKQueryNotification(fromRemoteNotificationDictionary: userInfo as! [String : NSObject])

    if notification.notificationType == .Query {
        let queryNotification = notification
        if queryNotification.queryNotificationReason  == .RecordUpdated {
           print("queryNotification.recordID \(queryNotification.recordID)")
        }
    }
   }


text:
Q: angular 2 - how to import / inject a component during runtime Let's say that there are two views of product, and I want to show one of those views based on user preferences.
I am thinking to have two views <my-product> maintained at two different folders and after user logged in, I want to import from a folder based on how the user prefers to view the product.
Folder 1
----MyProductComponent //exports MyProductComponent with selector <my-product></my-product>
Folder 2
----MyProductComponent //exports MyProductComponent with selector <my-product></my-product>
App
----App.Component // here I would like to import the component at runtime from either folder 1 / 2 based on user preferences

Please share your insights on this. Are there any alternatives if this cannot be achieved at the component level (ex: at routing level).

A: Why not just have an *ngIf on two elements that will swap based on the users preference?
<my-product1 *ngIf="userPref1"></my-product1>
<my-product2 *ngIf="!userPref1"></my-product2>

Where userPref1 is a variable (or function) located on App.Component that gets set by user input.
Then the user can state their preference and the application will swap the views based upon their input and you no longer need to deal with importing at run-time.

A: You should use [ngSwitch] based on the user's preference and then in *ngSwitchCase load that particular component. In reality, you are not lazy loading your components. They are all preloaded, but you just use Angular's DOM manipulation methods to show or hide one component or the other.
For example:
<div [ngSwitch]="someUserPreference">
    <div *ngSwitchCase="grid">
        <my-grid-list></my-grid-list>
    </div>
    <div *ngSwitchCase="card">
        <my-card-view-grid></my-card-view-grid>
    </div>
    <div *ngSwitchDefault>
        <!-- Incorrect preference, let's show grid as a fallback -->
        <my-grid-list></my-grid-list>
    </div>
</div>

Basically, when a user changes their preference, this will be reflected in the code. Either they change the preference via a button, radio button, or whatever, you need to store that value in someUserPreference variable or property that will be used in the switch statement.


text:
Q: Hide RadGrid EditFormSettings control runtime Below is my code for a RadGrid edit form, and it's working fine but I want to hide place holder control ID="plupload" on Insert/Edit mode of EditFormSettings on RadComboBox1 index changed event.
Can anyone please help to fix this issue?
<editformsettings editformtype="Template">
    <FormTemplate>

                                Name:

                                <asp:TextBox ID="TextBox2" Text='<%# Bind( "Name") %>' runat="server" TabIndex="8">
                                </asp:TextBox>

                        <asp:PlaceHolder ID="plupload" runat="server" >

                                    File Upload :

                                    <telerik:RadAsyncUpload runat="server" ID="AsyncUpload1" OnClientFileUploaded="OnClientFileUploaded" MultipleFileSelection="Disabled" AllowedFileExtensions="jpg,jpeg,png,gif" MaxFileSize="1048576" onvalidatingfile="RadAsyncUpload1_ValidatingFile">
                                    </telerik:RadAsyncUpload>

                        </asp:PlaceHolder>

                    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>
                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>

    </FormTemplate>
</editformsettings>

Here is my RadComboBox code:
<telerik:RadComboBox ID="RadComboBox1" runat="server" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged" AutoPostBack="True">
    <Items>
        <telerik:RadComboBoxItem Value="1" Text="Show All" />
        <telerik:RadComboBoxItem Value="2" Text="Hide File Upload" />
    </Items>
</telerik:RadComboBox>

A: Since you did not mention where your RadComboBox is, I am assuming it is outside of the RadGrid control. If that is the case, I suggest you implement a custom method to recursively search for your Placeholder.
// search for a specified control in the given root control and all its children
public static Control FindControlRecursive(Control rootControl, string searchControlID)
{
    if (rootControl.ID == searchControlID) return rootControl;

    foreach (Control controlToSearch in rootControl.Controls)
    {
        Control controlToReturn = FindControlRecursive(controlToSearch, searchControlID);
        if (controlToReturn != null) return controlToReturn;
    }
    return null;
}

Then, in your page's code-behind, you can search for plupload and set its Visible attribute.
protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e))
{
    RadComboBox RadComboBox1 = (RadComboBox)sender;

    // Get the placeholder control nested inside the RadGrid
    Placeholder plupload = (Placeholder)FindControlRecursive(RadGrid1, "plupload");

    if (plupload != null)
    {
        if (RadComboBox1.SelectedValue == "2")
            plupload.Visible = false;
        else plupload.Visible = true;
    }
}


text:
Q: Chrome devtools extension for IndexedDB I am trying to build a tool that facilitates CRUD operations i.e., a GUI for IndexedDB in Chrome. When I opened the database connection in the chrome dev tools panel, I found out that it has a separate IndexedDB store for panel.html for itself. Panel cannot access the current page's database.
Is there any way we can access page's database from a chrome dev tool's extension panel.

A: The current page's IndexedDB can't be accessed from within the extension (or the extension's dev tools) due to security reasons:

"IndexedDB uses the same-origin principle, which means that it ties the store to the origin of the site that creates it (typically, this is the site domain or subdomain)." https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#Security

But as pointed out by aug it is possible to request cross-origin permissions:

"By adding hosts or host match patterns (or both) to the permissions section of the manifest file, the extension can request access to remote servers outside of its origin." https://developer.chrome.com/extensions/xhr#requesting-permission


text:
Q: Function that works as a try except lambda function in a dataframe I'm trying to clean the column of a dataframe so only the first name is left.
What I'm currently trying is splitting each value of the column into a list, and then gathering the [0] of the list, if the element contains a comma, then get the [1].
I try the code below and it works perfectly, except for some outlier values that only have the last name with a comma, but no first name as shown in the examples below:
What I used:
msgDFt['From Name'] = msgDFt['From Name'].str.split(' ')
msgDFt['From Name'] = msgDFt['From Name'].apply(lambda row: row[0] if ',' not in row[0] else row[1])

Now I'm aware that lambda functions do not have the feature of having a try-except, the next thing  I tried was a function:
def firstNameMod(name):
    for n in name:
        if n[0] == None:
            name = 'NOT FOUND'
        elif ',' in n[0]:
            name = name[1]
        elif ',' in n[0] and n[1] == None:
            name = name[0]
        elif n[0] != False:
            name = name[0]

df.apply(firstNameMod(df['Name']))

This did not work because the column I'm selected is being read as a NoneType.
What I have:
    Name
0   Robert Marin
1   Katherine Ortiz
2   Sloth, Herbert
3   Perez,

What I want:
    Name
0   Robert
1   Katherine
2   Herbert
3   NaN

sample dataframe:
names = {'Name': ['Robert Marin','Katherine Ortiz', 'Sloth, Herbert','Perez,']}
df = pd.DataFrame(names)

A: You can use a regex to extract your first name:
df['Name'].str.extract('(^\w+(?=[^,]*$)|(?<=, )\w+)')[0]

output:
0       Robert
1    Katherine
2      Herbert
3          NaN


text:
Q: Cannot do a POST request from React app to Wordpress Rest Api (ERR_EMPTY_RESPONSE) I'm running a ReactApp (with Create-React-App) on localhost. I am trying to create a post on a Wordpress website with Rest Api. I'm using Axios. The wordpress site is hosted on a live server.
Chrome gives me the following network error:
https://i.imgur.com/wA5pYTz.png
Firefox:
https://i.imgur.com/P5nie4W.png
I checked the server logs. And there is no record of the app accessing the API. It also almost immediately gives me errors.
The strange thing is: whenever I do this from Postman or from a basic NodeJS file (with the same code) it just works and I receive a 201 response:
Postman:
https://i.imgur.com/THmRSZ1.png
I have setup CORS headers on the Rest Api server.
What can I try to fix this?
The Axios code:
axios({
    method: 'post',
    'headers': {
      "Authorization": 'Bearer HIDDEN'
    },
    url: 'HIDDEN/wp-json/wp/v2/posts',
    data: {
      title: "Test"
    }
  }).then(function(response) {
    console.log(response);
  })
  .catch(function(error) {
    console.log(error);
  });

A: Using WordPress rest API you have to pass nonce, because WordPress now use nonce, for doing adding, deleting somethings so you should care of nonce.


text:
Q: Why does Webpack 2 output only one of my images? I'm still fairly new to webpack 2 but I've got most of my configurations working so far. The only thing I'm having some difficulty understanding is that when I run "npm run build" to bundle my files into my "dist" folder I noticed that only 1 of my images are being bundled. I'm using 'file-loader'. FYI all my images still show on my dev-server when I run it and appear under the public paths I assigned. It's only my local output that's not displaying all the images. Anyone know what's going on?
My Folder Structure

webpack.config.js
module.exports = {
    mode: "development",
    entry: {
        app: "app"
    },
    output: {
        path: path.resolve(__dirname, "dist"),
        filename: "[name].bundle.js",
        publicPath: "/"
    },
    devServer: {
        publicPath: '/',
        port: 3000
    },
    module: {
        rules: [
            {
                test: /\.(png|svg|jpg|gif)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: '[name].[ext]',
                            outputPath: 'images/',
                            publicPath: 'images/'
                        }
                    }
                ]
            }
        ]
    }
}

As you can see in my folder structure, it always builds with only one of my images being outputted. It's not a major issue (I don't think) since all the images still work when I run the app, but I would appreciate it if anyone could help me understand why only one image is outputting to my local 'dist'. Thank you.

A: Webpack only writes images to disk that you require. This is one of the benefits of Webpack, it only includes assets that your application needs, so Webpack will guarantee those images exist when you deploy.
To add more images to your output, require them either from your Javascript or CSS with url()s
Note that if you're using the dev server, Webpack doesn't write anything to disk, and keeps all compiled assets in memory.


text:
Q: Align items at the start and end of div css I want my items in my div to align at the start and end of the div. However, I'm using bootstrap and I have no idea how do this.

A: You could use a flexbox with the justify-content-between class:

.main {
  border: 1px solid black;
  width: 40vw;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

  <Button class="m-2">
  Button 1
  </Button>
  <Button class="m-2">
  Button 2
  </Button>

A: Add bootstrap classes in the parent div
More info
d-flex  justify-content-between

A: you can use the d-flex and justify-content-between classes provided by Bootstrap.

<!doctype html>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap demo</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">

              <button type="button" class="btn btn-primary">Primary</button>
              <button type="button" class="btn btn-primary">Primary</button>


text:
Q: Drools - load KJAR from classpath or dependency related at pom.xml I'm developing a BPM application with Drools, integrated inside a Spring boot project. To create a kContainer object I'm using the @KContainer annotation:
@KContainer
@KReleaseId(groupId = "group", artifactId = "kjar", version = "LATEST")
private KieContainer kContainer;

In local and QA environments Drools search the kjar artifact using maven in a remote repository and all works fine. But, for security reasons, in production environment, it's not possible to search the artifact, because the server cannot have access to the maven repository. I'm including into the pom.xml file the dependency for kjar project, but when I review the logs, I can see that it's avoiding to search in classpath.
My question is, how can I force to Drools to load the KJAR dependency from the classpath and libraries inside de project jar instead of make requests to maven's repository?
Thanks in advance.

A: Assuming you have added kjar in your classpath.
Drools KIE API provides a mechanism to load kjar from the classpath. Hope below java code snippets help you to create KIE container using classpath kjar.
KieServices kieServices = KieServices.Factory.get();
KieContainer kieContainer = kieServices.getKieClasspathContainer();


text:
Q: Exit shell script if file doesn't exist Ive got a .sql job which creates files depending on certain criteria, it writes these with a prefix of TEMP_ as we then have an adaptor that picks up the files and we dont want them picked up before writing is complete.
I need to put a post job in place which renames these files, i have it set up with a number of other job but they all create the files each time they run. This job only creates the files sometimes it runs, depending on the data in the system.
I need to do a check if the file exists and then exit if no file exists.
Ive found a few examples but they all seem to fail, this is where i have got to which i thought was checking if no file, if no file then exit but it fails and displays:
"syntax error at line 16: `TEMP_SUBCON*.csv' unexpected"
This is what i have currently with line 16 being the first line - Above that is just comments:
    if [[ ! -f $OUT_DIR -name TEMP_SUBCON*.csv ]] ; then
    exit $?
    fi

    TEMP_DATA_FILE=$(find $OUT_DIR -name TEMP_SUBCON_QTY_output*.csv)
    DATA_FILE=$(basename $TEMP_DATA_FILE | cut -c6-)

    echo $TEMP_DATA_FILE
    echo $DATA_FILE

## Rename the file name, remove the phrase TEMP_, so that EAI can pick the file ##
mv $TEMP_DATA_FILE $OUT_DIR/$DATA_FILE

Can you help guide what ive done incorrectly?
Thanks

A: That syntax is not valid for the [[ ... ]] test.
Why not use the result of the subsequent find command to check if there were any matching files in the specified directory instead, and quit if no files are returned (in other words, quit if the result variable is empty)?
Example:
TEMP_DATA_FILE=$(find $OUT_DIR -name "TEMP_SUBCON_QTY_output*.csv" )
if [[ -z ${TEMP_DATA_FILE:=""} ]]  ; then
   exit 1
fi

Note 1: you should quote the pattern argument for the find command as shown.
Note 2:  it is useful to use set -u in your ksh scripts to cause ksh to abort if variables are unitialized when used (often the cause of errors) , instead of using a default value. However, if you use use set -u then in any test you should explicitly give your own default value. That is the reason for using ${TEMP_DATA_FILE:=""} instead of ${TEMP_DATA_FILE} - to support the often very useful set -u option. Even when you do not use set -u the ${TEMP_DATA_FILE:=""} inside tests makes it explicit what should happen instead of relying on implicit behaviour.
Note 3: you should use set -x when debugging and study every line of the output, it will show you exactly what commands ran with which arguments and what was the result. This helps you to learn how to code in ksh and similar shells.

A: If I understand it right, you want to find the files with TEMP_ prefix in your $OUT_DIR, and then if any rename them without the prefix. Then that should do the trick
for file in $OUT_DIR/TEMP_SUBCON_*.txt; do
    if [[ -e $file ]]; then
        mv $file $OUT_DIR/${file#*SUBCON_}
    fi
done
exit

It will go through the directory finding each TEMP_ file and rename them without it. If there is none, it won't do anything.


text:
Q: Is it possible to only have some parts of an app support an iPad view? We're looking to create an app that has 2 interfaces depending on what type of user logs in. The first user type (customer) will be using the app on their iPhone (almost exclusively) and the second user type (merchant) will be using it on their iPad (also almost exclusively). There are budget constraints preventing us from making both interfaces flexible to support both of these types of screen sizes.
What options do we have from a development perspective that allow us to create an experience that both of these user types will best benefit from? Do we need to submit 2 separate apps to the app store to achieve this or is there some other fancy way?

A: Apple Guidelines

Important: It is strongly recommended that your iPad applications
  support all orientations. This includes portrait, portrait
  upside-down, landscape left and landscape right. iPad apps that
  require an orientation must support both variants of that orientation.

Which basically means, if you want to support iPad, you have no other option than to allow both variants of a single orientation (atleast). This will make the UI easy to support both iPad and iPhone, however:

depending on what type of user logs in.

The main question here is: Does your "merchant" run strictly and only on iPad? If so, then the clean way is probably to have 2 apps, that way you can control the content and code since you probably are showing different UI etc to your merchant/customers. If you have many differences in code and UI, you are best to go with 2 apps in my opinion.
However, no matter how you twist and turn, the ammount of work that needs to be taken into account for any option, depends on a list of other factors and can't be answered here, (would take a developer to go through your code/Design/project and estimate the work)
EDIT:
You have no "fancy" option to support 2 different devices and by any fancy methods choose who is allowed to use your app with what device after they have installed your product through App Store. Apple will and should reject that.

A: Make it support for both iPad and iPhone Applications depending on user. If anyone enters from wrong platform detect and give a message to them.
It also awareness your users that they are supposed to use iPad or iPhone only.
And you can check the platform by using the code:
#define IDIOM    UI_USER_INTERFACE_IDIOM()
#define IPAD     UIUserInterfaceIdiomPad

if ( IDIOM == IPAD ) {
    /* do something specifically for iPad. */
} else {
    /* do something specifically for iPhone or iPod touch. */
}


text:
Q: Реализация движения танка по консоли Pygame Вопрос из серии: "почему не работает?" Есть программа (код ниже), реализующая передвижение танка по экрану. За движение отвечают кнопки WASD (впрочем, как обычно). В левом нижнем углу окна есть квадратики, которые меняют цвет, если нажата соответствующая кнопка (из WASD), и меняют его обратно при отпускании. Также нужно добавить текстовое отображение направления движения танка. В этом-то и заключается вся проблема: функционал этого текстового отчета есть, а почему не работает - ума не приложу.
За отображение текста отвечает класс Text, за саму отрисовку - функция draw, которая, в свою очередь вызывается в классах: UpCommand, DownCommand,  LeftCommand и RightCommand.
Вот сам код:
import sys
from abc import ABC, abstractmethod
from math import cos, sin, pi

import pygame

class Color:
    RED = (255, 0, 0)
    GREEN = (0, 255, 0)

class PG:
    _instance = None

    def __init__(self, width=500, height=400):
        if PG._instance is not None:  # singleton implementation
            raise ReferenceError('Tying to create singleton object twice')
        else:
            PG._instance = self
        pygame.init()
        self.screen = pygame.display.set_mode((width, height))
        self.width = width
        self.height = height

    @staticmethod
    def get():
        if not PG._instance:
            PG()
        return PG._instance

class PGObject(ABC):
    def __init__(self):
        self.screen = PG.get().screen

    def draw(self, string):
        pass

    def logic(self):
        pass

class PGScene(ABC):
    bgcolor = (0, 0, 0)

    def __init__(self):
        self.screen = PG.get().screen
        self.sceneover = False
        self.objects = []

    def draw(self):
        self.screen.fill(self.bgcolor)
        for item in self.objects:
            item.draw()

    def process_events(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.sceneover = True
            self.process_event(event)

    def process_event(self, event):
        pass

    @abstractmethod
    def process_logic(self):
        for item in self.objects:
            item.logic()

    def main_loop(self):
        while not self.sceneover:
            self.process_events()
            self.process_logic()
            self.draw()
            pygame.display.flip()
            pygame.time.wait(10)

class GameScene(PGScene):

    def __init__(self):
        super().__init__()
        self.panzer = Panzer(200, 200)
        self.buttons = {
            'up': StateRect(100, 500, 20, 20, Color.GREEN, Color.RED),
            'down': StateRect(100, 530, 20, 20, Color.GREEN, Color.RED),
            'left': StateRect(70, 530, 20, 20, Color.GREEN, Color.RED),
            'right': StateRect(130, 530, 20, 20, Color.GREEN, Color.RED),
        }
        self.objects.append(self.panzer)
        self.objects += self.buttons.values()

    def process_logic(self):
        super().process_logic()

    def process_event(self, event):
        if event.type == pygame.KEYUP and event.key in KeyUpMoment.keyup_events.keys():
            KeyUpMoment.keyup_events[event.key](self).execute()
        if event.type == pygame.KEYDOWN and event.key in KeyDownMoment.keydown_events.keys():
            KeyDownMoment.keydown_events[event.key](self).execute()

class Text(PGObject):
    def __init__(self):
        super().__init__()
        pygame.font.init()
        self.font = pygame.font.SysFont('Comic Sans MS', 14, None)
        self.color = Color.GREEN

    def draw(self, string):
        text = self.font.render(string, False, self.color)
        self.screen.blit(text, (250, 150))

class Command(ABC):
    def __init__(self, scene):
        self.scene = scene

    @abstractmethod
    def execute(self):
        pass

class UpCommand(Command):
    def execute(self):
        self.scene.panzer.move()
        self.scene.buttons['up'].set_enabled(True)
        self.scene.buttons['down'].set_enabled(False)
        UpText = Text()
        UpText.draw('движение вперёд')
        print('движение вперёд')

class DownCommand(Command):
    def execute(self):
        self.scene.panzer.move_back()
        self.scene.buttons['down'].set_enabled(True)
        self.scene.buttons['up'].set_enabled(False)
        DownText = Text()
        DownText.draw('движение назад')
        print('движение назад')

class LeftCommand(Command):
    def execute(self):
        self.scene.panzer.rotate(-0.5)
        self.scene.buttons['left'].set_enabled(True)
        self.scene.buttons['right'].set_enabled(False)
        LeftText = Text()
        LeftText.draw('движение влево')
        print('движение влево')

class RightCommand(Command):
    def execute(self):
        self.scene.panzer.rotate(0.5)
        self.scene.buttons['right'].set_enabled(True)
        self.scene.buttons['left'].set_enabled(False)
        RightText = Text()
        RightText.draw('движение вправо')
        print('движение вправо')

class KeyDownMoment(GameScene):
    keydown_events = {
        pygame.K_w: UpCommand,
        pygame.K_s: DownCommand,
        pygame.K_a: LeftCommand,
        pygame.K_d: RightCommand,
    }

class StopCommand(Command):
    def execute(self):
        self.scene.panzer.stop()

class StopUpCommand(StopCommand):
    def execute(self):
        super().execute()
        self.scene.buttons['up']

class StopDownCommand(StopCommand):
    def execute(self):
        super().execute()
        self.scene.buttons['down']

class StopLeftCommand(StopCommand):
    def execute(self):
        super().execute()
        self.scene.buttons['left']

class StopRightCommand(StopCommand):
    def execute(self):
        super().execute()
        self.scene.buttons['right']

class KeyUpMoment(GameScene):
    keyup_events = {
        pygame.K_w: StopUpCommand,
        pygame.K_s: StopDownCommand,
        pygame.K_a: StopLeftCommand,
        pygame.K_d: StopRightCommand
    }

class Panzer(PGObject):
    def __init__(self, x, y):
        super().__init__()
        self.rotated_image = self.image = pygame.image.load("panzer.png")
        self.rotated_rect = self.rect = self.image.get_rect()
        self.x = x
        self.y = y
        self.direction = 0
        self.speed = 0
        self.max_speed = 1

    def draw(self):
        self.rect.x = self.x - self.rect.width // 2
        self.rect.y = self.y - self.rect.height // 2
        self.rotated_rect = self.rotated_image.get_rect(center=self.rect.center)
        self.screen.blit(self.rotated_image, self.rotated_rect)

    def move(self):
        self.speed = self.max_speed

    def move_back(self):
        self.speed = -self.max_speed

    def stop(self):
        self.speed = 0

    def step(self):
        self.x += cos(self.direction) * self.speed
        self.y += sin(self.direction) * self.speed

    def rotate(self, angle):
        self.direction += angle
        self.rotated_image = pygame.transform.rotate(self.image, -self.direction / pi * 180)
        self.rotated_rect = self.rotated_image.get_rect(center=self.rect.center)

    def logic(self):
        self.step()

class StateRect(PGObject):
    def __init__(self, x, y, width, height, color_enabled, color_disabled):
        super().__init__()
        self.rect = (x, y, width, height)
        self.color_enabled = color_enabled
        self.color_disabled = color_disabled
        self.enabled = False

    def draw(self):
        color = self.color_enabled if self.enabled else self.color_disabled,
        pygame.draw.rect(self.screen, color, self.rect, 0)

    def set_enabled(self, enabled):
        self.enabled = enabled

if __name__ == "__main__":
    PG(800, 600)
    gs = GameScene()
    gs.main_loop()
    sys.exit()

Помогите, пожалуйста, с задачей. Если вдруг увидите ошибку, пожалуйста, подскажите решение проблемы. Заранее спасибо


text:
Q: Java Client Socket Connection in Android I am creating a client socket connection between my computer and android.
Here is the code for the server:
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

class Server {
  public static void main(String[] args) {
    String ip = getIpAddress();

    if (ip != "false") {
        try {
            ServerSocket srvr = new ServerSocket(4444);

        Socket client = null;
        try {
            client = srvr.accept();

            PrintWriter out = new PrintWriter(client.getOutputStream(), true);
            System.out.print("Sending ip address: '" + ip + "'\n");
            out.print(ip);
            out.close();
            client.close();
            srvr.close();
        } catch(Exception e) {
            System.out.print(String.format("Accept failed: %s",e));
        }
        } catch (Exception e) {
            System.out.print(String.format("Could not listem on port: %s",e));
        }
    }
    else
    {
        System.out.print("Could not get ip address");
    }
  }

  public static String getIpAddress() {
    InetAddress host;
    String ipString = "false";

    try {
        host = InetAddress.getLocalHost();
        ipString = host.getHostAddress();
    } catch (UnknownHostException e) {
        System.out.println(e);
    }

    return ipString;
  }
}

When I run the client on the computer everything works.
Here is the code for the computer client:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class Client {
  public static void main(String[] args) {
    System.out.print(RunSocketClient());
  }

  public static String RunSocketClient() {
    try {
        Socket clnt = new Socket("localhost",4444);
        BufferedReader in = new BufferedReader(new InputStreamReader(clnt.getInputStream()));

        String fromServer;
        fromServer = in.readLine();

        return fromServer;
    } catch (IOException e) {
        return "nothing";
    }
  }
}

When I run the this client code in android the system stops working, what is the error?
Here is the android client code:
package com.example.clientapp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LinearLayout lView = new LinearLayout(this);

    TextView myText = new TextView(this);
    String ip = RunSocketClient();
    Log.d("ClientApp",ip);
    myText.setText(ip);

    lView.addView(myText);

    setContentView(lView);
  }

  public static String RunSocketClient() {
    try {
        Socket clnt = new Socket("localhost",4444);
        BufferedReader in = new BufferedReader(new InputStreamReader(clnt.getInputStream()));

        String fromServer;
        fromServer = in.readLine();

        return fromServer;
    } catch (IOException e) {
        return "nothing";
    }
  }
}

Here is the logcat of the application crash:
04-13 00:10:31.411: D/AndroidRuntime(13978): Shutting down VM

04-13 00:10:31.411: W/dalvikvm(13978): threadid=1: thread exiting with uncaught exception (group=0x410ab300)

04-13 00:10:31.411: E/AndroidRuntime(13978): FATAL EXCEPTION: main

04-13 00:10:31.411: E/AndroidRuntime(13978): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.clientapp/com.example.clientapp.MainActivity}: android.os.NetworkOnMainThreadException

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.app.ActivityThread.access$600(ActivityThread.java:130)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.os.Handler.dispatchMessage(Handler.java:99)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.os.Looper.loop(Looper.java:137)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.app.ActivityThread.main(ActivityThread.java:4745)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at java.lang.reflect.Method.invokeNative(Native Method)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at java.lang.reflect.Method.invoke(Method.java:511)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at dalvik.system.NativeStart.main(Native Method)

04-13 00:10:31.411: E/AndroidRuntime(13978): Caused by: android.os.NetworkOnMainThreadException

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at java.net.InetAddress.lookupHostByName(InetAddress.java:385)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at java.net.InetAddress.getAllByName(InetAddress.java:214)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at java.net.Socket.tryAllAddresses(Socket.java:108)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at java.net.Socket.<init>(Socket.java:177)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at java.net.Socket.<init>(Socket.java:149)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at com.example.clientapp.MainActivity.RunSocketClient(MainActivity.java:34)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at com.example.clientapp.MainActivity.onCreate(MainActivity.java:23)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.app.Activity.performCreate(Activity.java:5008)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)

04-13 00:10:31.411: E/AndroidRuntime(13978):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)

04-13 00:10:31.411: E/AndroidRuntime(13978):    ... 11 more

A: In your application the NetworkOnMainThreadException is occurred. From the doc you ca see that

The exception that is thrown when an application attempts to perform a
  networking operation on its main thread.

So you have to call your RunSocketClient method from another thread rather than the main thread. Use a handler or asynctask or different thread to perform this operation.
To know about good designing you can see this link
http://developer.android.com/training/articles/perf-anr.html

A: add these line to AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
Without these permission you cannot access network resources...


text:
Q: Greek text in markdown or md I would like to write a few greek paragraphs in markdown or md file using a freeware editor such as Mdcharm etc. Is it possible and what exact headers I have to use?
A sample and complete example would help me a lot!
Regards


text:
Q: Common Lisp Implementations - threading and multiplatform? I'm learning Common Lisp, mostly as a "mind gym" hobby thing, but I want to end up with a set of skills that would also be usable "in real life", because when you learn a language you also accumulate knowledge about module and package management, deployment and stuff, whether you like it or not, so I want to learn with a CL implementation that is also usable in production. So my question is:
What CL implementation is most usable "in production", having attributes like these? :

*

*it's multi-platform - one should be able to use the same language implementation and languages on a Linux server, a Windows dev machine and a MacOS one (the coolest thing would be being able to also compile for Android, Windows Phone and RT and maybe even iOS)

*it has good concurrency, parallelism, multi-threading features - and these features work cross-platform, otherwise it doesn't count

*it's easy to interface with other languages - working with C libraries is a must, but anything else, like an easy CL-Python interface would be nice

I insist on the multi-platform part because I know that one of the serious arguments for Reddit ditching CL (CMUCL - btw, I know SBCL is fork of CMUCL, but how do they compare?) was that developers couldn't just use their Macs to develop without being ssh'd into a dev server environment (quote: "On my Mac, my choices of threaded Lisp implementations was limited to OpenMCL, and in FreeBSD it's CMUCL."). Yeah, one can use a dev VM, but still...

Note #1: I was close to settling on CLISP but I don't know about its concurrency features, and I also came across this: "it all-but-forces your code to be released as GPL" (I can't understand what this means or how can a languages's license become forced on your code, but I'm not fluent in legalese...).
Note #2: I'm not really fond of the JVM, and if I were to use a Lisp on it it would be Clojure and nothing else, so no JVM Lisps suggestions, please :)

A: Disclaimer:  I'm a (minor) contributor to SBCL, but I was a user first. As a happy user of CLISP, CMUCL, and SBCL, here's why SBCL is my "go to" CL implementation:
Steel Bank Common Lisp meets the criteria you mention:

*

*Runs on MacOS, Windows, and Linux (among other platforms)

*Provides an identical API for threading and concurrency control on all of these platforms

*Has a comprehensive foreign function interface to allow interfacing with C
In addition, SBCL is a good Lisp environment in general:

*

*it's a native Lisp -- no JVM, no bytecode

*it's well supported by SLIME and Quicklisp

*it's a mature and complete implementation

*it's actively developed, and I've seen good turnaround when I've hit bugs


text:
Q: Why cython not found? I'm trying to build deb files with obs(open build service), however, when I excute osc build --local-package, I got the error as below:
[  269s] make[1]: Entering directory '/usr/src/packages/BUILD'
[  269s] cython --cplus msgpack/*.pyx
[  269s] /bin/sh: 1: cython: not found
[  269s] Makefile:7: recipe for target 'cython' failed
[  269s] make[1]: *** [cython] Error 127
[  269s] make[1]: Leaving directory '/usr/src/packages/BUILD'
[  269s] dh_auto_build: make -j1 returned exit code 2
[  269s] debian/rules:18: recipe for target 'build' failed
[  269s] make: *** [build] Error 2
[  269s] dpkg-buildpackage: error: debian/rules build gave error exit status 2

It seems that /bin/sh doesn't found cython. while cython is install in my ubuntu.
$ which cython
/usr/bin/cython
$ cython --version
Cython version 0.23.4

Can anyone help me?
thanks


text:
Q: ArangoDB batch issue with sharded collections I have set up an arangodb 3.1.10 cluster on a single server with 3 agents, 5 coordinators and 5 primaries. I have an issue with using big batches with sharded collections.
I regularly get the following error in the coordinator responsible for the batch query:
2017-02-15T15:23:28Z [2665] ERROR {cluster} cannot create connection to server 'PRMR-6f3a5704-5500-4fa8-8933-5029e492c25d' at endpoint 'tcp://localhost:4101'
2017-02-15T15:23:28Z [2665] ERROR {cluster} cannot create connection to server 'PRMR-6f3a5704-5500-4fa8-8933-5029e492c25d' at endpoint 'tcp://localhost:4101'

Localhost:4101 is a PRIMARY. But its own log does not show any error:
2017-02-15T14:38:10Z [2582] INFO ArangoDB 3.1.10 [linux] 64bit, using VPack 0.1.30, ICU 54.1, V8 5.0.71.39, OpenSSL 1.0.1e-fips 11 Feb 2013
2017-02-15T14:38:10Z [2582] INFO using SSL options: SSL_OP_CIPHER_SERVER_PREFERENCE, SSL_OP_TLS_ROLLBACK_BUG
2017-02-15T14:38:10Z [2582] INFO Starting up with role PRIMARY
2017-02-15T14:38:27Z [2582] INFO {cluster} Fresh start. Persisting new UUID PRMR-6f3a5704-5500-4fa8-8933-5029e492c25d
2017-02-15T14:38:27Z [2582] INFO file-descriptors (nofiles) hard limit is 65536, soft limit is 65536
2017-02-15T14:38:27Z [2582] INFO WAL directory '/opt/arangodb/primary_4101/data/journals' does not exist. creating it...
2017-02-15T14:38:27Z [2582] INFO created base application directory '/opt/arangodb/primary_4101/apps/_db'
2017-02-15T14:38:27Z [2582] INFO JavaScript using startup '/usr/share/arangodb3/js', application '/opt/arangodb/primary_4101/apps'
2017-02-15T14:38:28Z [2582] INFO Cluster feature is turned on. Agency version: {"server":"arango","version":"3.1.10","license":"community"}, Agency endpoints: http+tcp://127.0.0.1:4002, http+tcp://127.0.0.1:4000, http+tcp://127.0.0.1:4001, server id: 'PRMR-6f3a5704-5500-4fa8-8933-5029e492c25d', internal address: tcp://localhost:4101, role: PRIMARY
2017-02-15T14:38:28Z [2582] INFO using heartbeat interval value '1000 ms' from agency
2017-02-15T14:38:28Z [2582] INFO using endpoint 'http+tcp://0.0.0.0:4101' for non-encrypted requests
2017-02-15T14:38:28Z [2582] INFO bootstrapped DB server PRMR-6f3a5704-5500-4fa8-8933-5029e492c25d
2017-02-15T14:38:28Z [2582] INFO ArangoDB (version 3.1.10 [linux]) is ready for business. Have fun!
2017-02-15T15:22:42Z [2582] INFO created application directory '/opt/arangodb/primary_4101/apps/_db/entities' for database 'entities'`

As long as the collection are not sharded it works fine, but as soon as I add sharding some of the batches just fail. When doing this test my collections all had 5 shards.
Here is the command I used to start the primary:
/usr/sbin/arangod \
--server.endpoint tcp://0.0.0.0:4101 \
--server.threads 8 \
--log.level INFO \
--javascript.v8-contexts 4 \
--database.directory /opt/arangodb/primary_4101/data \
--javascript.startup-directory /usr/share/arangodb3/js \
--javascript.app-path /opt/arangodb/primary_4101/apps \
--log.file /opt/arangodb/primary_4101/arangod.log \
--log.force-direct false \
--server.authentication false \
--cluster.my-address tcp://localhost:4101 \
--cluster.my-role PRIMARY \
--cluster.my-local-info tcp://localhost:4101 \
--foxx.queues false \
--server.statistics true \
--cluster.agency-endpoint tcp://localhost:4000 --cluster.agency-endpoint tcp://localhost:4001 --cluster.agency-endpoint tcp://localhost:4002


text:
Q: javaScript clear image source not working I am trying to convert a div with text and image into a single image then setting that image as my image source but the image is getting copied multiple times or getting error and code not working.
I am getting the text from textarea and then setting that text on the above of image and then converting that text and image into a single image by using html5canavs. Code is working fine but the issue is image is getting copied multiple times and if I am trying to clear the image it is not working.
Here's the image of how it is looking after overlapping multiple times.
Here's my code

window.onload = function() {

  }

  function myFunction() {
    var v = document.getElementById("mTextArea").value;
    document.getElementById("wow").innerHTML = v;

    html2canvas(document.getElementById("imagewrap"), {
      onrendered: function(canvas) {
        theCanvas = canvas;

        canvas.className = "html2canvas";
        var image = canvas.toDataURL("image/png");
        // document.body.removeChild("container2"); <<---Throwing Error
        document.getElementById("img_prev").src = image;
      },
      useCORS: true
    });
  }
*{
    font-family: 'Roboto', sans-serif;
}
#container1{
    float: left;
}
#container2{
    float: right;
}
#mImage{
    height: 300px;
    width: 300px;
}

.desc {
    position: absolute;
    text-align: center;
    top: 1px;
    left: 30px;
}
.outer, .wrap, .html2canvas, .image_text {
display: inline-block;
vertical-align: top;
}
.wrap {
text-align: center;
}
#imagewrap {
    position: relative;
background-color: white;
}
#wow {
    text-align: center;
    font-size: 25pt;
    position: absolute;
    color: red;
    display: block;
    top: 50px;
    left: 50px;
    right: 50px;
    align-items: center;
    word-wrap: break-word;
}
<!DOCTYPE html>

        <link rel="stylesheet" href="styles.css">

        <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap" rel="stylesheet">
        <title>Social Poster</title>

Social Poster

            <textarea name="inputT" id="mTextArea" cols="30" rows="10"></textarea>
            <button id="mButton" onclick="myFunction()">Click ME!</button>

                  WOW!

A: You are rendering the image ontop of its self causing the feedback effect.
Just use two images. Showing the background and text when you click render and when the result has rendered hide the original background and text just showing the result image.
Move the border out of the rendered image to stop the shrinking background.
Example

mButton.addEventListener("click",createImage);

function createImage() {
  // show text and background image
  wow.textContent = mTextArea.value;
  wow.classList.remove("hide");
  backgroundImage.classList.remove("hide");

  // hide prev rendered image
  resultImage.classList.add("hide");

  // render to canvas
  html2canvas(imagewrap, {
    onrendered(canvas) {
      // hide background and text image
      backgroundImage.classList.add("hide");
      backgroundImage.classList.add("hide");

      // show rendered image
      resultImage.classList.remove("hide");
      resultImage.src = canvas.toDataURL("image/png");
    },
    useCORS: true
  });
}
*{
    font-family: 'Roboto', sans-serif;
}
#container1{
    float: left;
}
#container2{
    float: right;
}
#mImage{
    height: 300px;
    width: 300px;
}

.desc {
    position: absolute;
    text-align: center;
    top: 1px;
    left: 30px;
}
.outer, .wrap, .html2canvas, .image_text {
  display: inline-block;
  vertical-align: top;
}
.wrap {
  text-align: center;
}
#imagewrap {
    position: relative;
    background-color: white;
}
#wow {
    text-align: center;
    font-size: 25pt;
    position: absolute;
    color: red;
    display: block;
    top: 50px;
    left: 50px;
    right: 50px;
    align-items: center;
    word-wrap: break-word;
}

.hide {
  display: none;
}
.resultBorder {
  border: solid;
}

<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap" rel="stylesheet">

Social Poster

    <textarea name="inputT" id="mTextArea" cols="30" rows="10"></textarea>
    <button id="mButton" >Create Image!</button>

          WOW!

A: Problem - Multiple images --  why?
After first click it captures the div into canvas.You can clearly see there is some border outside image. So after you are setting the image in the div to the "canvas created image" border will remain and the div captured into image will have inturn the border as its like screenshot of it.
Solution:
Remove the border and avoid spacing
Problem - Text over Text -- why?
You are setting the value of span with id "wow" to the value of text area whenever you click the "click me" button and then you are doing html2canvas which will make an image of div since you have span inside div with text it will also be there in the canvas.After canvas is generated you are setting the src of image to canvas.toDataURL(). When you again click on "click me" with different text , it will place the text on current image(which already has some previous text)
Solution:
Set the text of the span with id="wow" after img.src=canvas.toDateURL()

function myFunction() {
   document.getElementById("wow").innerHTML =""
    html2canvas(document.getElementById("imagewrap"), {
      onrendered: function(canvas) {
        var image = canvas.toDataURL();
      document.getElementById("img_prev").src = image
      document.getElementById("wow").innerHTML =
      document.getElementById("mTextArea").value;
      },
      useCORS: true
    });
  }
*{
    font-family: 'Roboto', sans-serif;
}
#container1{
    float: left;
}
#container2{
    float: right;
}
#mImage{
    height: 300px;
    width: 300px;
}

.desc {
    position: absolute;
    text-align: center;
    top: 1px;
    left: 30px;
}
.outer, .wrap, .html2canvas, .image_text {
display: inline-block;
vertical-align: top;
}
.wrap {
text-align: center;
}
#imagewrap {
    position: relative;
background-color: white;
}
#wow {
    text-align: center;
    font-size: 25pt;
    position: absolute;
    color: red;
    display: block;
    top: 50px;
    left: 50px;
    right: 50px;
    align-items: center;
    word-wrap: break-word;
}
<!DOCTYPE html>

        <link rel="stylesheet" href="styles.css">

        <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap" rel="stylesheet">
        <title>Social Poster</title>

Social Poster

            <textarea name="inputT" id="mTextArea" cols="30" rows="10"></textarea>
            <button id="mButton" onclick="myFunction()">Click ME!</button>

                  WOW!


text:
Q: I'm getting this error "ReferenceError: responceBody is not defined" i have written my test script code like this
var responce=JSON.parse(responceBody);

tests["scope"] = responce.scope == "APP";

A: There's a typo in your responseBody variable, try: JSON.parse(responseBody)


text:
Q: STXXL fails at creating a map of strings in long numeric With the code that follows, I want to create a map of type std::map. By using a debugger, I got that the exception was raised by stl_pair.h at line 368 (pair& operator=(typename conditional<__and_<is_copy_assignable<_T1>, is_copy_assignable<_T2>>::value, const pair&, const __wrap_nonesuch&>::type __p)), which was invoked by the map scanning of cur (*(cur + 1) = *cur;) in the leaf.h insert function of stxxl. I provide the code I used in the following source code:
#include <stxxl/map>
#include <fstream>
#include <string>
#include <cstdint>

typedef uint_fast64_t LONG_NUMERIC;
std::string random_string( size_t length )
{
    auto randchar = []() -> char
    {
        const char charset[] =
                "0123456789"
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                        "abcdefghijklmnopqrstuvwxyz";
        const size_t max_index = (sizeof(charset) - 1);
        return charset[ rand() % max_index ];
    };
    std::string str(length,0);
    std::generate_n( str.begin(), length, randchar );
    return str;
}

struct CompareGreater22
{
    bool operator () (const std::string& a, const std::string& b) const
    { return a > b; }
    static std::string max_value()
    { return std::string(); }
};

int main(int argc, char** argv) {

    stxxl::config * cfg = stxxl::config::get_instance();
    stxxl::disk_config disk1("/mnt/DEC4763AC47614CD/stxxl.tmp", 100 * 1024 * 1024, "syscall unlink");
    disk1.direct = stxxl::disk_config::DIRECT_ON; // force O_DIRECT
    // add disk to config
    cfg->add_disk(disk1);

    // template parameter <KeyType, DataType, CompareType, RawNodeSize, RawLeafSize, PDAllocStrategy (optional)>
    typedef stxxl::map<std::string, LONG_NUMERIC, CompareGreater22, DATA_NODE_BLOCK_SIZE, DATA_LEAF_BLOCK_SIZE> map_type3;
    // Constructor map(node_cache_size_in_bytes, leaf_cache_size_in_bytes)
    map_type3 t((map_type3::node_block_type::raw_size)*3, (map_type3::leaf_block_type::raw_size)*3);

    //vertex_conversion_map_type t{(vertex_conversion_map_type::node_block_type::raw_size)*3, (vertex_conversion_map_type::leaf_block_type::raw_size)*3};
    for (LONG_NUMERIC i = 0; i< 2000; i++) {
        t.insert(std::make_pair(random_string(10), i));
    }
 }

I also provide the dump result:
[STXXL-MSG] STXXL v1.4.99 (prerelease/Debug) (git 0a80a8c55993948f7f2f6c2c5a51ff45b403045b) + gnu parallel(20170406)
[STXXL-MSG] Disk '/mnt/DEC4763AC47614CD/stxxl.tmp' is allocated, space: 100 MiB, I/O implementation: syscall direct=on queue=0 devid=0 unlink_on_open
*** Error in `/anon/software/path': free(): invalid pointer: 0x000055c0cd7688d0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7908b)[0x7fd69ff1108b]
/lib/x86_64-linux-gnu/libc.so.6(+0x82c3a)[0x7fd69ff1ac3a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fd69ff1ed2c]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_assignERKS4_+0xaf)[0x7fd6a0ad0fcf]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSERKS4_+0x9)[0x7fd6a0ad1339]
/anon/software/path(+0x19bfb)[0x55c0cc841bfb]
/anon/software/path(+0x15699)[0x55c0cc83d699]
/anon/software/path(+0x10dba)[0x55c0cc838dba]
/anon/software/path(+0xf6fc)[0x55c0cc8376fc]
/anon/software/path(+0xd46d)[0x55c0cc83546d]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7fd69feb83f1]
/anon/software/path(+0xd01a)[0x55c0cc83501a]
======= Memory map: ========
55c0cc828000-55c0cc9d8000 r-xp 00000000 08:02 509986                     /anon/software/path
55c0ccbd7000-55c0ccbdc000 r--p 001af000 08:02 509986                     /anon/software/path
55c0ccbdc000-55c0ccbdd000 rw-p 001b4000 08:02 509986                     /anon/software/path
55c0ccbdd000-55c0ccbdf000 rw-p 00000000 00:00 0
55c0cd74a000-55c0cd78c000 rw-p 00000000 00:00 0                          [heap]
7fd698000000-7fd698021000 rw-p 00000000 00:00 0
7fd698021000-7fd69c000000 ---p 00000000 00:00 0
7fd69f697000-7fd69f698000 ---p 00000000 00:00 0
7fd69f698000-7fd69fe98000 rw-p 00000000 00:00 0
7fd69fe98000-7fd6a0056000 r-xp 00000000 103:05 795936                    /lib/x86_64-linux-gnu/libc-2.24.so
7fd6a0056000-7fd6a0255000 ---p 001be000 103:05 795936                    /lib/x86_64-linux-gnu/libc-2.24.so
7fd6a0255000-7fd6a0259000 r--p 001bd000 103:05 795936                    /lib/x86_64-linux-gnu/libc-2.24.so
7fd6a0259000-7fd6a025b000 rw-p 001c1000 103:05 795936                    /lib/x86_64-linux-gnu/libc-2.24.so
7fd6a025b000-7fd6a025f000 rw-p 00000000 00:00 0
7fd6a025f000-7fd6a0275000 r-xp 00000000 103:05 791133                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd6a0275000-7fd6a0474000 ---p 00016000 103:05 791133                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd6a0474000-7fd6a0475000 r--p 00015000 103:05 791133                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd6a0475000-7fd6a0476000 rw-p 00016000 103:05 791133                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd6a0476000-7fd6a04a3000 r-xp 00000000 103:05 4335250                   /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
7fd6a04a3000-7fd6a06a2000 ---p 0002d000 103:05 4335250                   /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
7fd6a06a2000-7fd6a06a3000 r--p 0002c000 103:05 4335250                   /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
7fd6a06a3000-7fd6a06a4000 rw-p 0002d000 103:05 4335250                   /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
7fd6a06a4000-7fd6a07ac000 r-xp 00000000 103:05 795940                    /lib/x86_64-linux-gnu/libm-2.24.so
7fd6a07ac000-7fd6a09ab000 ---p 00108000 103:05 795940                    /lib/x86_64-linux-gnu/libm-2.24.so
7fd6a09ab000-7fd6a09ac000 r--p 00107000 103:05 795940                    /lib/x86_64-linux-gnu/libm-2.24.so
7fd6a09ac000-7fd6a09ad000 rw-p 00108000 103:05 795940                    /lib/x86_64-linux-gnu/libm-2.24.so
7fd6a09ad000-7fd6a0b26000 r-xp 00000000 103:05 4335931                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fd6a0b26000-7fd6a0d25000 ---p 00179000 103:05 4335931                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fd6a0d25000-7fd6a0d2f000 r--p 00178000 103:05 4335931                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fd6a0d2f000-7fd6a0d31000 rw-p 00182000 103:05 4335931                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fd6a0d31000-7fd6a0d35000 rw-p 00000000 00:00 0
7fd6a0d35000-7fd6a0d4d000 r-xp 00000000 103:05 795951                    /lib/x86_64-linux-gnu/libpthread-2.24.so
7fd6a0d4d000-7fd6a0f4d000 ---p 00018000 103:05 795951                    /lib/x86_64-linux-gnu/libpthread-2.24.so
7fd6a0f4d000-7fd6a0f4e000 r--p 00018000 103:05 795951                    /lib/x86_64-linux-gnu/libpthread-2.24.so
7fd6a0f4e000-7fd6a0f4f000 rw-p 00019000 103:05 795951                    /lib/x86_64-linux-gnu/libpthread-2.24.so
7fd6a0f4f000-7fd6a0f53000 rw-p 00000000 00:00 0
7fd6a0f53000-7fd6a0f79000 r-xp 00000000 103:05 795932                    /lib/x86_64-linux-gnu/ld-2.24.so
7fd6a114b000-7fd6a1150000 rw-p 00000000 00:00 0
7fd6a1174000-7fd6a1178000 rw-p 00000000 00:00 0
7fd6a1178000-7fd6a1179000 r--p 00025000 103:05 795932                    /lib/x86_64-linux-gnu/ld-2.24.so
7fd6a1179000-7fd6a117a000 rw-p 00026000 103:05 795932                    /lib/x86_64-linux-gnu/ld-2.24.so
7fd6a117a000-7fd6a117b000 rw-p 00000000 00:00 0
7fff9e622000-7fff9e643000 rw-p 00000000 00:00 0                          [stack]
7fff9e714000-7fff9e716000 r--p 00000000 00:00 0                          [vvar]
7fff9e716000-7fff9e718000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

A: TL;DR: Your KeyType is a std::string and consequently non-pod. The STXXL does not support this.

*

*See section Parameterizing STXXL Containers in the official STXXL FAQ.

*See How to use std::string as key in stxxl::map here, where somebody had the same issue. Answers below that question describe possible workarounds.


text:
Q: Blank texture when disabling mipmaping? I do not master all the subtlety of OpenGL so sorry if my question is not precise enough
On iPhone I load a texture (png image) like this
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iTextureSize.width, iTextureSize.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_FILTER, GL_NEAREST);

Which works well but I noticed that this allocate exactly twice the size of textureData.
I've read in forums that this could be caused by mipmaping so I tried to turn it off by
commenting the glTexParameteri lines but then my textures is blank.
Is this a problem is my texture loading parameter on in my display code ?
My display code is like this
glTexCoordPointer(2, GL_FLOAT, 0, texture);
glVertexPointer(DIMENSION,  GL_SHORT,  0, iVertex);
glBindTexture(GL_TEXTURE_2D, (GLuint)textureID);
glDrawArrays(GL_TRIANGLE_FAN,  0, iVertexCount);

A: Now that you have mipmaps disabled alright, have you tried to disable the texture repeat ?
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

If your texture width or height is a value that is not a power of two, you fall into the 'non-power-of-two texture' (NPOT), which is handled with limitations on iPhone, see :
Rendering to non-power-of-two texture on iPhone

A: Commenting out the two texture parameter lines enables MIP mapping. Since you upload only one level of texture, all the other levels are blank. That's why you subsequently don't see anything.
By what means are you concluding that you're causing twice the size of textureData to be allocated and how do you reach the conclusion that this is an error? It's up to the GL driver how it allocates memory internally and where it caches what it wants. There's no reason to assume that double is incorrect, especially if you're adding video RAM to main RAM.
Furthermore, storing MIP maps adds one third to your overall storage requirements, not 100%.


text:
Q: Pass over duplicate comparing for each results This is a tough one. I'm completely stumped here.
Basically I have this :
    foreach ($getSubsSecondList as $subCatDisplayExtendTwoSecondList){

    $itemUse = $subCatDisplayExtendTwoSecondList[dir_sub_categories];

    if (!empty($itemUse)) {
    if (isset($itemUse)) {
    foreach (array_unique($getSubsSecondListAgain) as $subCatDisplayExtendTwoSecondListAgain){
echo "
";
var_dump($itemUse);
echo "

";
$nameStore = $subCatDisplayExtendTwoSecondListAgain[name];

    }
    }
    }
    }

For my $itemUse var_dump I have an output of

string(16) "Health & Fitness"
string(6) "Sports"
string(17) "Sports - Training"
string(19) "Sports & Recreation"

Exactly what I'm looking for. The problem is I have Sports Store #1 in "Health and fitness" and in the "Sports" category. Sports Store #1 is echoed twice. Is there a way to further break this down so that if Sports Store #1 is found more than once it will by pass it? The actual output here is
Sports Store # 0
Sports Store # 1
Sports Store # 1

What I'm looking for is only one instance to appear like so:
Sports Store # 0
Sports Store # 1

A: Store what you output into an array, and if the next thing you want to output is in the array, don't print it out and move on to the next element.
 $outputted = array();

 foreach ($getSubsSecondList as $subCatDisplayExtendTwoSecondList){

    $itemUse = $subCatDisplayExtendTwoSecondList[dir_sub_categories];

    if (!empty($itemUse)) {
      if (isset($itemUse)) {
        foreach (array_unique($getSubsSecondListAgain) as $subCatDisplayExtendTwoSecondListAgain){
          if ( in_array($subCatDisplayExtendTwoSecondListAgain[name], $outputted) ){
             continue;
          }
          echo "
";
          var_dump($itemUse);
          echo "

";

          echo $subCatDisplayExtendTwoSecondListAgain[name];
          $outputted[] = $subCatDisplayExtendTwoSecondListAgain[name];

        }
     }
    }
   }


text:
Q: Printing a names in java? Can you tell me how to solve that problem ?
Scanner scanner = new Scanner(System.in);
 package Exercise2501;

    import java.util.Scanner;

    public class Friends
    {

       public static void main(String[] args)
       {

          Scanner scanner = new Scanner(System.in);
          System.out.println("How many names do you want to enter?");
          int number = scanner.nextInt();
          for (int i = 0; i < number; i++)
          {
          System.out.println("Type a few names. ");
          String names = scanner.nextLine();
          }
          String names = scanner.nextLine();
          System.out.println(names);

       }

    }

A:     package Exercise2501;
    import java.util.Scanner;

    public class Friends {

    public static void main(String[] args) {

      Scanner scanner = new Scanner(System.in);
      //Get the number of entries
      System.out.println("How many names do you want to enter?");
      int number = scanner.nextInt();
      //create an array with that number
      String names[] = new names[number];
      //Ask the user to enter the Names
      System.out.println("Type a few names. ");
      //Store the names in the array
      for (int i = 0; i < number; i++)
      {
          names[i] = scanner.nextLine();
      }
      //Do the remaining you want
    }

    }


text:
Q: Text should be printed in new line when text is longer than field width I am really new to JasperReports and have the following issue:
I would like to print the date with time zone in some colum but the colum width is not enough for printing the date:

How to tell jasper that it has to print the time zone in new line? something like this:
2016-07-07 16:32:35 +02:00
EUROPE/BERLIN

I use Jaspersoft iReport Desinger 4.7.0.
UPDATE:
the field looks like this:
<field name="date" class="java.lang.String"/>
..
..
<textField isStretchWithOverflow="true">
                <reportElement uuid="6e3cbfd4-f1e9-453f-b3d8-39ae6231931d" key="element-1863" style="column details" stretchType="RelativeToBandHeight" x="626" y="0" width="216" height="12"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
            </textField>
..
....


text:
Q: save picture and open in imageview When I take a picture, the picture will saved on the hard drive and open the picture in imageview.
In my command the picture will be saved but the app is crashing.
public class Note  extends Activity {

TextView t;
ImageView iv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.note);
   iv=(ImageView) findViewById(R.id.imageView);

    Button btn = (Button) findViewById(R.id.photo);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, 0);
        }
    });

}
public void button (View view){
    Intent intent = new Intent(view.getContext(),Note2.class);
    startActivityForResult(intent, 0);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode==0)
    {
    Bitmap theImage = (Bitmap) data.getExtras().get("data");
        iv.setImageBitmap(theImage);

    }}
}

How do I rewrite the command to make it work?
 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode==0)
        {
        Bitmap theImage = (Bitmap) data.getExtras().get("data");
            iv.setImageBitmap(theImage);

A: First, make sure that your Manifest has this permissions:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Second, your onActivityResult method should be like this with declaring a File and store the Bitmap into the device as following:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch(requestCode){
  case 0:
    final File file = getTempFile(this);
    try {
      Bitmap captureBmp = Media.getBitmap(getContentResolver(), Uri.fromFile(file) );
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  break;
  }
}
}

Here is a very good example on capturing images


text:
Q: Does OAuth 2.0 covers End-User acting of behalf of another End-User? My needs:

*

*Let's consider 2 end-users of the same domain.

*User UA is the resource owner of resource RA.

*User UA wants to delegate access of resource RA to end-user UB.

My main OAuth 2.0 interest comes from total token control (revocation at any time, etc.).

OAuth 2.0 Framework allows a client to act on the behalf of a resource owner with it's explicit permissions.
Oauth 2.0 defines resource owner and client roles (see the roles section) where:

*

*Resource owner can be an end-user (that can grant access to a protected resource).

*Client is an application making protected resource requests on behalf of the resource owner.

In the spec, the client is always considered as an application (with no particular implementation characteristics).
I would like to know if it is ok to implement OAuth 2.0 with an end-user as the client role or am I abusing OAuth completely?
My intuition is that OAuth 2.0 is only designed for third party application (with interoperability) and not for 2 end-users of the same domain. Am I right? In the other hand all the token mechanism really fits my needs.

PS: This expired OAuth specification (2010) talks about delegating authorization by a Resource Owner to another user via a Client using the OAuth protocol. But it's not that relevant.

A:
I would like to know if it is ok to implement OAuth 2.0 with an
  end-user as the client role or am I abusing OAuth completely?

Well, it is only an opinion of mine, but if, say, a Buffer can represent me posting my contents to Facebook using OAuth, why my friend Jack (a human, not robot) can't?
Of course, you must think it all over, especially in terms of security. But the abstract scheme looks fine by me.