问:
ggplot with 2 y axes on each side and different scales
I need to plot a bar chart showing counts and a line chart showing rate all in one chart, I can do both of them separately, but when I put them together, I scale of the first layer (i.e. the geom_bar) is overlapped by the second layer (i.e. the geom_line).

Can I move the axis of the geom_line to the right?

Body:
For me the tricky part was figuring out the transformation function between the two axis. I used myCurveFit for that.

> dput(combined_80_8192 %>% filter (time > 270, time < 280))
structure(list(run = c(268L, 268L, 268L, 268L, 268L, 268L, 268L,
268L, 268L, 268L, 263L, 263L, 263L, 263L, 263L, 263L, 263L, 263L,
263L, 263L, 269L, 269L, 269L, 269L, 269L, 269L, 269L, 269L, 269L,
269L, 261L, 261L, 261L, 261L, 261L, 261L, 261L, 261L, 261L, 261L,
267L, 267L, 267L, 267L, 267L, 267L, 267L, 267L, 267L, 267L, 265L,
265L, 265L, 265L, 265L, 265L, 265L, 265L, 265L, 265L, 266L, 266L,
266L, 266L, 266L, 266L, 266L, 266L, 266L, 266L, 262L, 262L, 262L,
262L, 262L, 262L, 262L, 262L, 262L, 262L, 264L, 264L, 264L, 264L,
264L, 264L, 264L, 264L, 264L, 264L, 260L, 260L, 260L, 260L, 260L,
260L, 260L, 260L, 260L, 260L), repetition = c(8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), module = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "scenario.node[0].nicVLCTail.phyVLC", class = "factor"),
    configname = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L), .Label = "Road-Vlc", class = "factor"), packetByteLength = c(8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L,
    8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L, 8192L
    ), numVehicles = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
    ), dDistance = c(80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
    80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
    80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
    80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
    80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
    80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
    80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
    80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
    80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L), time = c(270.166006903445,
    271.173853699836, 272.175873251122, 273.177524313334, 274.182946177105,
    275.188959464989, 276.189675339937, 277.198250244799, 278.204619457189,
    279.212562800009, 270.164199199177, 271.168527215152, 272.173072994958,
    273.179210429715, 274.184351047337, 275.18980754378, 276.194816792995,
    277.198598277809, 278.202398083519, 279.210634593917, 270.210674322891,
    271.212395107473, 272.218871923292, 273.219060500457, 274.220486359614,
    275.22401452372, 276.229646658839, 277.231060448138, 278.240407241942,
    279.2437126347, 270.283554249858, 271.293168593832, 272.298574288769,
    273.304413221348, 274.306272082517, 275.309023049011, 276.317805897347,
    277.324403550028, 278.332855848701, 279.334046374594, 270.118608539613,
    271.127947700074, 272.133887145863, 273.135726000491, 274.135994529981,
    275.136563912708, 276.140120735361, 277.144298344151, 278.146885137621,
    279.147552358659, 270.206015567272, 271.214618077209, 272.216566814903,
    273.225435592582, 274.234014573683, 275.242949179958, 276.248417809711,
    277.248800670023, 278.249750333404, 279.252926560188, 270.217182684494,
    271.218357511397, 272.224698488895, 273.231112784327, 274.238740508457,
    275.242715184122, 276.249053562718, 277.250325509798, 278.258488063493,
    279.261141590137, 270.282904173953, 271.284689544638, 272.294220723234,
    273.299749415592, 274.30628880553, 275.312075103126, 276.31579134717,
    277.321905523606, 278.326305136748, 279.333056502253, 270.258991527456,
    271.260224091407, 272.270076810133, 273.27052037648, 274.274119348094,
    275.280808254502, 276.286353887245, 277.287064312339, 278.294444793276,
    279.296772014594, 270.333066283904, 271.33877455992, 272.345842319903,
    273.350858180493, 274.353972278505, 275.360454510107, 276.365088896161,
    277.369166956941, 278.372571708911, 279.38017503079), distanceToTx = c(80.255266401689,
    80.156059067023, 79.98823695539, 79.826647129071, 79.76678667135,
    79.788239825292, 79.734539327997, 79.74766421514, 79.801243848241,
    79.765920888341, 80.255266401689, 80.15850240049, 79.98823695539,
    79.826647129071, 79.76678667135, 79.788239825292, 79.735078924078,
    79.74766421514, 79.801243848241, 79.764622734914, 80.251248121732,
    80.146436869316, 79.984682320466, 79.82292012342, 79.761908518748,
    79.796988776281, 79.736920997657, 79.745038376718, 79.802638836686,
    79.770029970452, 80.243475525691, 80.127918207499, 79.978303140866,
    79.816259117883, 79.749322030693, 79.809916018889, 79.744456560867,
    79.738655068783, 79.788697533211, 79.784288359619, 80.260412958482,
    80.168426829066, 79.992034911214, 79.830845773284, 79.7756751763,
    79.778156038931, 79.732399593756, 79.752769548846, 79.799967731078,
    79.757585110481, 80.251248121732, 80.146436869316, 79.984682320466,
    79.822062073459, 79.75884601899, 79.801590491435, 79.738335109094,
    79.74347007248, 79.803215965043, 79.771471198955, 80.250257298678,
    80.146436869316, 79.983831684476, 79.822062073459, 79.75884601899,
    79.801590491435, 79.738335109094, 79.74347007248, 79.803849157574,
    79.771471198955, 80.243475525691, 80.130180105198, 79.978303140866,
    79.816881283718, 79.749322030693, 79.80984572883, 79.744456560867,
    79.738655068783, 79.790548644175, 79.784288359619, 80.246349000313,
    80.137056554491, 79.980581246037, 79.818924707937, 79.753176142361,
    79.808777040341, 79.741609845588, 79.740770913572, 79.796316397253,
    79.777593733292, 80.238796415443, 80.119021911134, 79.974810568944,
    79.814065350562, 79.743657315504, 79.810146783217, 79.749945098869,
    79.737122584544, 79.781650522348, 79.791554933936), headerNoError = c(0.99999999989702,
    0.9999999999981, 0.99999999999946, 0.9999999928026, 0.99999873265475,
    0.77080141574964, 0.99007491438593, 0.99994396605059, 0.45588747062284,
    0.93484381262491, 0.99999999989702, 0.99999999999816, 0.99999999999946,
    0.9999999928026, 0.99999873265475, 0.77080141574964, 0.99008458785106,
    0.99994396605059, 0.45588747062284, 0.93480223051707, 0.99999999989735,
    0.99999999999789, 0.99999999999946, 0.99999999287551, 0.99999876302649,
    0.46903147501117, 0.98835168988253, 0.99994427085086, 0.45235035271542,
    0.93496741877335, 0.99999999989803, 0.99999999999781, 0.99999999999948,
    0.99999999318224, 0.99994254156311, 0.46891362282273, 0.93382613917348,
    0.99994594904099, 0.93002915596843, 0.93569767251247, 0.99999999989658,
    0.99999999998074, 0.99999999999946, 0.99999999272802, 0.99999871586781,
    0.76935240919896, 0.99002587758346, 0.99999881589732, 0.46179415706093,
    0.93417422376389, 0.99999999989735, 0.99999999999789, 0.99999999999946,
    0.99999999289347, 0.99999876940486, 0.46930769326427, 0.98837353639905,
    0.99994447154714, 0.16313586712094, 0.93500824170148, 0.99999999989744,
    0.99999999999789, 0.99999999999946, 0.99999999289347, 0.99999876940486,
    0.46930769326427, 0.98837353639905, 0.99994447154714, 0.16330039178981,
    0.93500824170148, 0.99999999989803, 0.99999999999781, 0.99999999999948,
    0.99999999316541, 0.99994254156311, 0.46794586553266, 0.93382613917348,
    0.99994594904099, 0.9303627789484, 0.93569767251247, 0.99999999989778,
    0.9999999999978, 0.99999999999948, 0.99999999311433, 0.99999878195152,
    0.47101897739483, 0.93368891853679, 0.99994556595217, 0.7571113417265,
    0.93553999975802, 0.99999999998191, 0.99999999999784, 0.99999999999971,
    0.99999891129658, 0.99994309267792, 0.46510628979591, 0.93442584181035,
    0.99894450514543, 0.99890078483692, 0.76933812306423), receivedPower_dbm = c(-93.023492290586,
    -92.388378035287, -92.205716340607, -93.816400586752, -95.023489422885,
    -100.86308557253, -98.464763536915, -96.175707680373, -102.06189538385,
    -99.716653422746, -93.023492290586, -92.384760627397, -92.205716340607,
    -93.816400586752, -95.023489422885, -100.86308557253, -98.464201120719,
    -96.175707680373, -102.06189538385, -99.717150021506, -93.022927803442,
    -92.404017215549, -92.204561341714, -93.814319484729, -95.016990717792,
    -102.01669022332, -98.558088145955, -96.173817001483, -102.07406915124,
    -99.71517574876, -93.021813165972, -92.409586309743, -92.20229160243,
    -93.805335867418, -96.184419849593, -102.01709540787, -99.728735187547,
    -96.163233028048, -99.772547164798, -99.706399753853, -93.024204617071,
    -92.745813384859, -92.206884754512, -93.818508150122, -95.027018807793,
    -100.87000577258, -98.467607232407, -95.005311380324, -102.04157607608,
    -99.724619517, -93.022927803442, -92.404017215549, -92.204561341714,
    -93.813803344588, -95.015606885523, -102.0157405687, -98.556982278361,
    -96.172566862738, -103.21871579865, -99.714687230796, -93.022787428238,
    -92.404017215549, -92.204274688493, -93.813803344588, -95.015606885523,
    -102.0157405687, -98.556982278361, -96.172566862738, -103.21784988098,
    -99.714687230796, -93.021813165972, -92.409950613665, -92.20229160243,
    -93.805838770576, -96.184419849593, -102.02042267497, -99.728735187547,
    -96.163233028048, -99.768774335378, -99.706399753853, -93.022228914406,
    -92.411048503835, -92.203136463155, -93.807357409082, -95.012865008237,
    -102.00985717796, -99.730352912911, -96.165675535906, -100.92744056572,
    -99.708301333236, -92.735781110993, -92.408137395049, -92.119533319039,
    -94.982938427575, -96.181073124017, -102.03018610927, -99.721633629806,
    -97.32940323644, -97.347613268692, -100.87007386786), snr = c(49.848348091678,
    57.698190927109, 60.17669971462, 41.529809724535, 31.452202106925,
    8.1976890851341, 14.240447804094, 24.122884195464, 6.2202875499406,
    10.674183333671, 49.848348091678, 57.746270018264, 60.17669971462,
    41.529809724535, 31.452202106925, 8.1976890851341, 14.242292077376,
    24.122884195464, 6.2202875499406, 10.672962852322, 49.854827699773,
    57.49079026127, 60.192705735317, 41.549715223147, 31.499301851462,
    6.2853718719014, 13.937702343688, 24.133388256416, 6.2028757927148,
    10.677815810561, 49.867624820879, 57.417115267867, 60.224172277442,
    41.635752021705, 24.074540962859, 6.2847854917092, 10.644529778044,
    24.19227425387, 10.537686730745, 10.699414795917, 49.84017267426,
    53.139646558768, 60.160512118809, 41.509660845114, 31.42665220053,
    8.1846370024428, 14.231126423354, 31.584125885363, 6.2494585568733,
    10.654622041348, 49.854827699773, 57.49079026127, 60.192705735317,
    41.55465351989, 31.509340361646, 6.2867464196657, 13.941251828322,
    24.140336174865, 4.765718874642, 10.679016976694, 49.856439162736,
    57.49079026127, 60.196678846453, 41.55465351989, 31.509340361646,
    6.2867464196657, 13.941251828322, 24.140336174865, 4.7666691818074,
    10.679016976694, 49.867624820879, 57.412299088098, 60.224172277442,
    41.630930975211, 24.074540962859, 6.279972363168, 10.644529778044,
    24.19227425387, 10.546845071479, 10.699414795917, 49.862851240855,
    57.397787176282, 60.212457625018, 41.61637603957, 31.529239767749,
    6.2952688513108, 10.640565481982, 24.178672145334, 8.0771089950663,
    10.694731030907, 53.262541905639, 57.43627424514, 61.382796189332,
    31.747253311549, 24.093100244121, 6.2658701281075, 10.661949889074,
    18.495227442305, 18.417839037171, 8.1845086722809), frameId = c(15051,
    15106, 15165, 15220, 15279, 15330, 15385, 15452, 15511, 15566,
    15019, 15074, 15129, 15184, 15239, 15298, 15353, 15412, 15471,
    15526, 14947, 14994, 15057, 15112, 15171, 15226, 15281, 15332,
    15391, 15442, 14971, 15030, 15085, 15144, 15203, 15262, 15321,
    15380, 15435, 15490, 14915, 14978, 15033, 15092, 15147, 15198,
    15257, 15312, 15371, 15430, 14975, 15034, 15089, 15140, 15195,
    15254, 15313, 15368, 15427, 15478, 14987, 15046, 15105, 15160,
    15215, 15274, 15329, 15384, 15447, 15506, 14943, 15002, 15061,
    15116, 15171, 15230, 15285, 15344, 15399, 15454, 14971, 15026,
    15081, 15136, 15195, 15258, 15313, 15368, 15423, 15478, 15039,
    15094, 15149, 15204, 15263, 15314, 15369, 15428, 15487, 15546
    ), packetOkSinr = c(0.99999999314881, 0.9999999998736, 0.99999999996428,
    0.99999952114066, 0.99991568416005, 3.00628034688444e-08,
    0.51497487795954, 0.99627877136019, 0, 0.011303253101957,
    0.99999999314881, 0.99999999987726, 0.99999999996428, 0.99999952114066,
    0.99991568416005, 3.00628034688444e-08, 0.51530974419663,
    0.99627877136019, 0, 0.011269851265775, 0.9999999931708,
    0.99999999985986, 0.99999999996428, 0.99999952599145, 0.99991770469509,
    0, 0.45861812482641, 0.99629897628155, 0, 0.011403119534097,
    0.99999999321568, 0.99999999985437, 0.99999999996519, 0.99999954639936,
    0.99618434878558, 0, 0.010513119213425, 0.99641022914441,
    0.00801687746446111, 0.012011103529927, 0.9999999931195,
    0.99999999871861, 0.99999999996428, 0.99999951617905, 0.99991456738049,
    2.6525298291169e-08, 0.51328066587104, 0.9999212220316, 0,
    0.010777054258914, 0.9999999931708, 0.99999999985986, 0.99999999996428,
    0.99999952718674, 0.99991812902805, 0, 0.45929307038653,
    0.99631228046814, 0, 0.011436292559188, 0.99999999317629,
    0.99999999985986, 0.99999999996428, 0.99999952718674, 0.99991812902805,
    0, 0.45929307038653, 0.99631228046814, 0, 0.011436292559188,
    0.99999999321568, 0.99999999985437, 0.99999999996519, 0.99999954527918,
    0.99618434878558, 0, 0.010513119213425, 0.99641022914441,
    0.00821047996950475, 0.012011103529927, 0.99999999319919,
    0.99999999985345, 0.99999999996519, 0.99999954188106, 0.99991896371849,
    0, 0.010410830482692, 0.996384831822, 9.12484388049251e-09,
    0.011877185067536, 0.99999999879646, 0.9999999998562, 0.99999999998077,
    0.99992756868677, 0.9962208785486, 0, 0.010971897073662,
    0.93214999078663, 0.92943956665979, 2.64925478221656e-08),
    snir = c(49.848348091678, 57.698190927109, 60.17669971462,
    41.529809724535, 31.452202106925, 8.1976890851341, 14.240447804094,
    24.122884195464, 6.2202875499406, 10.674183333671, 49.848348091678,
    57.746270018264, 60.17669971462, 41.529809724535, 31.452202106925,
    8.1976890851341, 14.242292077376, 24.122884195464, 6.2202875499406,
    10.672962852322, 49.854827699773, 57.49079026127, 60.192705735317,
    41.549715223147, 31.499301851462, 6.2853718719014, 13.937702343688,
    24.133388256416, 6.2028757927148, 10.677815810561, 49.867624820879,
    57.417115267867, 60.224172277442, 41.635752021705, 24.074540962859,
    6.2847854917092, 10.644529778044, 24.19227425387, 10.537686730745,
    10.699414795917, 49.84017267426, 53.139646558768, 60.160512118809,
    41.509660845114, 31.42665220053, 8.1846370024428, 14.231126423354,
    31.584125885363, 6.2494585568733, 10.654622041348, 49.854827699773,
    57.49079026127, 60.192705735317, 41.55465351989, 31.509340361646,
    6.2867464196657, 13.941251828322, 24.140336174865, 4.765718874642,
    10.679016976694, 49.856439162736, 57.49079026127, 60.196678846453,
    41.55465351989, 31.509340361646, 6.2867464196657, 13.941251828322,
    24.140336174865, 4.7666691818074, 10.679016976694, 49.867624820879,
    57.412299088098, 60.224172277442, 41.630930975211, 24.074540962859,
    6.279972363168, 10.644529778044, 24.19227425387, 10.546845071479,
    10.699414795917, 49.862851240855, 57.397787176282, 60.212457625018,
    41.61637603957, 31.529239767749, 6.2952688513108, 10.640565481982,
    24.178672145334, 8.0771089950663, 10.694731030907, 53.262541905639,
    57.43627424514, 61.382796189332, 31.747253311549, 24.093100244121,
    6.2658701281075, 10.661949889074, 18.495227442305, 18.417839037171,
    8.1845086722809), ookSnirBer = c(8.8808636558081e-24, 3.2219795637026e-27,
    2.6468895519653e-28, 3.9807779074715e-20, 1.0849324265615e-15,
    2.5705217057696e-05, 4.7313805615763e-08, 1.8800438086075e-12,
    0.00021005320203921, 1.9147343768384e-06, 8.8808636558081e-24,
    3.0694773489537e-27, 2.6468895519653e-28, 3.9807779074715e-20,
    1.0849324265615e-15, 2.5705217057696e-05, 4.7223753038869e-08,
    1.8800438086075e-12, 0.00021005320203921, 1.9171738578051e-06,
    8.8229427230445e-24, 3.9715925056443e-27, 2.6045198111088e-28,
    3.9014083702734e-20, 1.0342658440386e-15, 0.00019591630514278,
    6.4692014108683e-08, 1.8600094209271e-12, 0.0002140067535655,
    1.9074922485477e-06, 8.7096574467175e-24, 4.2779443633862e-27,
    2.5231916788231e-28, 3.5761615214425e-20, 1.9750692814982e-12,
    0.0001960392878411, 1.9748966344895e-06, 1.7515881895994e-12,
    2.2078334799411e-06, 1.8649940680806e-06, 8.954486301678e-24,
    3.2021085732779e-25, 2.690441113724e-28, 4.0627628846548e-20,
    1.1134484878561e-15, 2.6061691733331e-05, 4.777159157954e-08,
    9.4891388749738e-16, 0.00020359398491544, 1.9542110660398e-06,
    8.8229427230445e-24, 3.9715925056443e-27, 2.6045198111088e-28,
    3.8819641115984e-20, 1.0237769828158e-15, 0.00019562832342849,
    6.4455095380046e-08, 1.8468752030971e-12, 0.0010099091367628,
    1.9051035165106e-06, 8.8085966897635e-24, 3.9715925056443e-27,
    2.594108048185e-28, 3.8819641115984e-20, 1.0237769828158e-15,
    0.00019562832342849, 6.4455095380046e-08, 1.8468752030971e-12,
    0.0010088638355194, 1.9051035165106e-06, 8.7096574467175e-24,
    4.2987746909572e-27, 2.5231916788231e-28, 3.593647329558e-20,
    1.9750692814982e-12, 0.00019705170257492, 1.9748966344895e-06,
    1.7515881895994e-12, 2.1868296425817e-06, 1.8649940680806e-06,
    8.7517439682173e-24, 4.3621551072316e-27, 2.553168170837e-28,
    3.6469582463164e-20, 1.0032983660212e-15, 0.00019385229409318,
    1.9830820164805e-06, 1.7760568361323e-12, 2.919419915209e-05,
    1.8741284335866e-06, 2.8285944348148e-25, 4.1960751547207e-27,
    7.8468215407139e-29, 8.0407329049747e-16, 1.9380328071065e-12,
    0.00020004849911333, 1.9393279417733e-06, 5.9354475879597e-10,
    6.4258355913627e-10, 2.6065221215415e-05), ookSnrBer = c(8.8808636558081e-24,
    3.2219795637026e-27, 2.6468895519653e-28, 3.9807779074715e-20,
    1.0849324265615e-15, 2.5705217057696e-05, 4.7313805615763e-08,
    1.8800438086075e-12, 0.00021005320203921, 1.9147343768384e-06,
    8.8808636558081e-24, 3.0694773489537e-27, 2.6468895519653e-28,
    3.9807779074715e-20, 1.0849324265615e-15, 2.5705217057696e-05,
    4.7223753038869e-08, 1.8800438086075e-12, 0.00021005320203921,
    1.9171738578051e-06, 8.8229427230445e-24, 3.9715925056443e-27,
    2.6045198111088e-28, 3.9014083702734e-20, 1.0342658440386e-15,
    0.00019591630514278, 6.4692014108683e-08, 1.8600094209271e-12,
    0.0002140067535655, 1.9074922485477e-06, 8.7096574467175e-24,
    4.2779443633862e-27, 2.5231916788231e-28, 3.5761615214425e-20,
    1.9750692814982e-12, 0.0001960392878411, 1.9748966344895e-06,
    1.7515881895994e-12, 2.2078334799411e-06, 1.8649940680806e-06,
    8.954486301678e-24, 3.2021085732779e-25, 2.690441113724e-28,
    4.0627628846548e-20, 1.1134484878561e-15, 2.6061691733331e-05,
    4.777159157954e-08, 9.4891388749738e-16, 0.00020359398491544,
    1.9542110660398e-06, 8.8229427230445e-24, 3.9715925056443e-27,
    2.6045198111088e-28, 3.8819641115984e-20, 1.0237769828158e-15,
    0.00019562832342849, 6.4455095380046e-08, 1.8468752030971e-12,
    0.0010099091367628, 1.9051035165106e-06, 8.8085966897635e-24,
    3.9715925056443e-27, 2.594108048185e-28, 3.8819641115984e-20,
    1.0237769828158e-15, 0.00019562832342849, 6.4455095380046e-08,
    1.8468752030971e-12, 0.0010088638355194, 1.9051035165106e-06,
    8.7096574467175e-24, 4.2987746909572e-27, 2.5231916788231e-28,
    3.593647329558e-20, 1.9750692814982e-12, 0.00019705170257492,
    1.9748966344895e-06, 1.7515881895994e-12, 2.1868296425817e-06,
    1.8649940680806e-06, 8.7517439682173e-24, 4.3621551072316e-27,
    2.553168170837e-28, 3.6469582463164e-20, 1.0032983660212e-15,
    0.00019385229409318, 1.9830820164805e-06, 1.7760568361323e-12,
    2.919419915209e-05, 1.8741284335866e-06, 2.8285944348148e-25,
    4.1960751547207e-27, 7.8468215407139e-29, 8.0407329049747e-16,
    1.9380328071065e-12, 0.00020004849911333, 1.9393279417733e-06,
    5.9354475879597e-10, 6.4258355913627e-10, 2.6065221215415e-05
    )), class = "data.frame", row.names = c(NA, -100L), .Names = c("run",
"repetition", "module", "configname", "packetByteLength", "numVehicles",
"dDistance", "time", "distanceToTx", "headerNoError", "receivedPower_dbm",
"snr", "frameId", "packetOkSinr", "snir", "ookSnirBer", "ookSnrBer"
))

Finding the transformation function

y1 --> y2
This function is used to transform the data of the secondary y axis to be "normalized" according to the first y axis

transformation function: f(y1) = 0.025*x + 2.75

y2 --> y1
This function is used to transform the break points of the first y axis to the values of the second y axis. Note that the axis are swapped now.

transformation function: f(y1) = 40*x - 110

Plotting

Note how the transformation functions are used in the ggplot call to transform the data "on-the-fly"

ggplot(data=combined_80_8192 %>% filter (time > 270, time < 280), aes(x=time) ) +
  stat_summary(aes(y=receivedPower_dbm ), fun.y=mean, geom="line", colour="black") +
  stat_summary(aes(y=packetOkSinr*40 - 110 ), fun.y=mean, geom="line", colour="black", position = position_dodge(width=10)) +
  scale_x_continuous() +
  scale_y_continuous(breaks = seq(-0,-110,-10), "y_first", sec.axis=sec_axis(~.*0.025+2.75, name="y_second") )

The first stat_summary call is the one that sets the base for the first y axis.
The second stat_summary call is called  to transform the data. Remember that all of the data will take as base the first y axis. So that data needs to be normalized for the first y axis. To do that I use the transformation function on the data: y=packetOkSinr*40 - 110

Now to transform the second axis I use the opposite function within the scale_y_continuous call: sec.axis=sec_axis(~.*0.025+2.75, name="y_second").


来源: stackexchange

问:
how to observe the events or detect the notification when the iOS system announce over a button or a label when VoiceOver is running?
When VoiceOver is running, I tapped a button, or a label, it will announce something about this button or label.
I want to do something when announcement completed. Is there some notifications to help me observe when the announcement is completed?
Thanks!</p>

答: Not exactly, no. However, and this is a terrible hack, you can monitor announcements that you, yourself, issue with UIAccessibilityPostNotification() by subscripting to the UIAccessibilityAnnouncementDidFinishNotification. Provided you queue up speech at the right times, it may be a reasonable assumption that any of your announcements finishing indicates that all system announcements have ended.

ContentLicense: CC BY-SA 3.0


问:
Spring Security 3.2

```<code>        use-expressions="true"
        entry-point-ref="unauthorizedEntryPoint"
        auto-config="true"

        authentication-manager-ref="authenticationManager" access-decision-manager-ref="accessDecisionManager">
    <!-- <custom-filter ref="authenticationTokenProcessingFilter" position="FORM_LOGIN_FILTER" /> -->
    <intercept-url pattern="/api/authenticate" access="ROLE_ADMIN" />
    <intercept-url pattern="/api/project/**" access="ROLE_ADMIN" />

    <logout delete-cookies="JSESSIONID" />
</http>
</code>```

```<code>        <beans:bean class="org.springframework.security.access.vote.RoleVoter">
            <beans:property name="rolePrefix" value="ROLE_"/>
        </beans:bean>

    </beans:list>
</beans:property>
</code>```

Throwing error

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0' while setting constructor argument with key [8]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Unsupported configuration attributes: [ROLE_ADMIN, ROLE_ADMIN]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:684)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5118)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5634)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0' while setting constructor argument with key [8]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Unsupported configuration attributes: [ROLE_ADMIN, ROLE_ADMIN]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:632)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    ... 26 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Unsupported configuration attributes: [ROLE_ADMIN, ROLE_ADMIN]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    ... 40 more
Caused by: java.lang.IllegalArgumentException: Unsupported configuration attributes: [ROLE_ADMIN, ROLE_ADMIN]
    at org.springframework.security.access.intercept.AbstractSecurityInterceptor.afterPropertiesSet(AbstractSecurityInterceptor.java:156)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
    ... 47 more

答:
You have configured use-expressions="true" so you cannot simply set the requested authority in the access attribute of the <intercept-url> elements.

You should do it this way:

```<code><intercept-url pattern="/api/authenticate" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/api/project/**" access="hasRole('ROLE_ADMIN')" />
</code>```

Or opposite to this, change use-expressions to false and let the intercepts the way you have them now.

Title: Spring Security 3.2

Body:
        use-expressions="true"
        entry-point-ref="unauthorizedEntryPoint"
        auto-config="true"

        authentication-manager-ref="authenticationManager" access-decision-manager-ref="accessDecisionManager">

    <intercept-url pattern="/api/authenticate" access="ROLE_ADMIN" />
    <intercept-url pattern="/api/project/**" access="ROLE_ADMIN" />

    <logout delete-cookies="JSESSIONID" />
</http>

        <beans:bean class="org.springframework.security.access.vote.RoleVoter">
            <beans:property name="rolePrefix" value="ROLE_"/>
        </beans:bean>

    </beans:list>
</beans:property>

Throwing error

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0' while setting constructor argument with key [8]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Unsupported configuration attributes: [ROLE_ADMIN, ROLE_ADMIN]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:684)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5118)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5634)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0' while setting constructor argument with key [8]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Unsupported configuration attributes: [ROLE_ADMIN, ROLE_ADMIN]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:632)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    ... 26 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Unsupported configuration attributes: [ROLE_ADMIN, ROLE_ADMIN]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    ... 40 more
Caused by: java.lang.IllegalArgumentException: Unsupported configuration attributes: [ROLE_ADMIN, ROLE_ADMIN]
    at org.springframework.security.access.intercept.AbstractSecurityInterceptor.afterPropertiesSet(AbstractSecurityInterceptor.java:156)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
    ... 47 more

Body:
You have configured use-expressions="true" so you cannot simply set the requested authority in the access attribute of the <intercept-url> elements.

You should do it this way:

<intercept-url pattern="/api/authenticate" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/api/project/**" access="hasRole('ROLE_ADMIN')" />

Or opposite to this, change use-expressions to false and let the intercepts the way you have them now.


问:
Disable PhpDoc by Default in PhpStorm Extract Method Refactoring Dialogue
I've searched PhpStorm's preferences, documentation, and Google to no avail.

Is there a way to disable by default the "Generate PhpDoc" option in PhpStorm's "Extract Method" dialogue?

答:
I know this is an ancient post, but I struggled with the same question today.  In PHPStorm 2017.1 the setting is here:

Preferences > Editor > Intentions > PHP > Generate PHPDoc for function


问:
PHP read first item in object array
I have my code in PHP which is returning this Array of data:

```<code>GoCardlessPro\Core\ListResponse Object
(
    [records] => Array
        (
            [0] => GoCardlessPro\Resources\Mandate Object
                (
                    [model_name:protected] => Mandate
                    [created_at:protected] => 2017-04-01T16:49:09.642Z
                    [id:protected] => ID001
                    [links:protected] => stdClass Object
                        (
                            [customer_bank_account] => CB001
                            [creditor] => CR001
                            [customer] => CU001
                        )

                    [metadata:protected] => stdClass Object
                        (
                        )

                    [next_possible_charge_date:protected] => 2017-04-06
                    [payments_require_approval:protected] =>
                    [reference:protected] => RE001
                    [scheme:protected] => bacs
                    [status:protected] => active
                    [data:GoCardlessPro\Resources\BaseResource:private] => stdClass Object
                        (
                            [id] => 123
                            [created_at] => 2017-04-01T16:49:09.642Z
                            [reference] => RE001
                            [status] => active
                            [scheme] => bacs
                            [next_possible_charge_date] => 2017-04-06
                            [payments_require_approval] =>
                            [metadata] => stdClass Object
                                (
                                )

                            [links] => stdClass Object
                                (
                                    [customer_bank_account] => 001
                                    [creditor] => CR001
                                    [customer] => CU001
                                )

                        )

                    [api_response] =>
                )

        )
)
</code>```

I want to be able to read the ID of the first item in therecords array.

This data is contained inside a variable called $GC_Mandate;

I have tried these:

```<code>echo $GC_Mandate->records->{0}->id;

echo $GC_Mandate->records->0->id;

echo $GC_Mandate->records->[0]->id;

$GC_Mandate = $GC_Mandate->records;
echo $GC_Mandate->{0}->id;
</code>```

But none will return the data

答:
To get the first record, the syntax you need is $GC_Mandate->records[ 0 ].

However, that object is a GoCardlessPro\Resources\Mandate object and its member id is protected1, so we'd need to know the interface of GoCardlessPro\Resources\Mandate (its public methods1), to know if we can somehow retrieve the value of id.

My guess would be getId(), so the full syntax would become

```<code>$GC_Mandate->records[ 0 ]->getId()
</code>```

But, that's just a guess. You'd have to look into the documentation/class definition of GoCardlessPro\Resources\Mandate, to be sure if you can retrieve id.

Turns out (provided I'm linking to the correct github repository) you can do:

```<code>$GC_Mandate->records[ 0 ]->id
</code>```

since GoCardlessPro\Resources\Mandate extends GoCardlessPro\Resources\BaseResource, which exposes the protected members through GoCardlessPro\Resources\BaseResource::__get()2.

1. visibility in PHP

2. magic methods in PHP

Title: PHP read first item in object array

Body:
I have my code in PHP which is returning this Array of data:

GoCardlessPro\Core\ListResponse Object
(
    [records] => Array
        (
            [0] => GoCardlessPro\Resources\Mandate Object
                (
                    [model_name:protected] => Mandate
                    [created_at:protected] => 2017-04-01T16:49:09.642Z
                    [id:protected] => ID001
                    [links:protected] => stdClass Object
                        (
                            [customer_bank_account] => CB001
                            [creditor] => CR001
                            [customer] => CU001
                        )

                    [metadata:protected] => stdClass Object
                        (
                        )

                    [next_possible_charge_date:protected] => 2017-04-06
                    [payments_require_approval:protected] =>
                    [reference:protected] => RE001
                    [scheme:protected] => bacs
                    [status:protected] => active
                    [data:GoCardlessPro\Resources\BaseResource:private] => stdClass Object
                        (
                            [id] => 123
                            [created_at] => 2017-04-01T16:49:09.642Z
                            [reference] => RE001
                            [status] => active
                            [scheme] => bacs
                            [next_possible_charge_date] => 2017-04-06
                            [payments_require_approval] =>
                            [metadata] => stdClass Object
                                (
                                )

                            [links] => stdClass Object
                                (
                                    [customer_bank_account] => 001
                                    [creditor] => CR001
                                    [customer] => CU001
                                )

                        )

                    [api_response] =>
                )

        )
)

I want to be able to read the ID of the first item in therecords array.

This data is contained inside a variable called $GC_Mandate;

I have tried these:

echo $GC_Mandate->records->{0}->id;

echo $GC_Mandate->records->0->id;

echo $GC_Mandate->records->[0]->id;

$GC_Mandate = $GC_Mandate->records;
echo $GC_Mandate->{0}->id;

But none will return the data

Body:
To get the first record, the syntax you need is $GC_Mandate->records[ 0 ].

However, that object is a GoCardlessPro\Resources\Mandate object and its member id is protected1, so we'd need to know the interface of GoCardlessPro\Resources\Mandate (its public methods1), to know if we can somehow retrieve the value of id.

My guess would be getId(), so the full syntax would become

$GC_Mandate->records[ 0 ]->getId()

But, that's just a guess. You'd have to look into the documentation/class definition of GoCardlessPro\Resources\Mandate, to be sure if you can retrieve id.

Turns out (provided I'm linking to the correct github repository) you can do:

$GC_Mandate->records[ 0 ]->id

since GoCardlessPro\Resources\Mandate extends GoCardlessPro\Resources\BaseResource, which exposes the protected members through GoCardlessPro\Resources\BaseResource::__get()2.

1. visibility in PHP

2. magic methods in PHP


问:
How I can multiline the expanded title of CollapsingToolbarLayout?
My problem is the next. I would use relatively large texts as CollapsingToolbarLayout title so I need to show it as multiline mode. When I try to change text appearance through the setExpandedTitleTextAppearance() method it doesn't work. The code who I used is the next:

```<code><style name="ToolbarExpandedTitle">
    <item name="android:textSize">48sp</item>
    <item name="android:shadowColor">#ffffff</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:singleLine">false</item>
    <item name="android:minLines">3</item>
    <item name="android:lines">4</item>
    <item name="android:maxLines">5</item>
</style>
</code>```

I would like to see the title on multiple lines instead of showing the ellipsis.

答:
A simpler approach would be to add a custom layout added to the CollapsingToolbar and pin it.

Some of the notes to take care:

The the toolbar should have the height of your collapsed content, this can be done by code or at the XML.

The elements you want to hide must be BEFORE the toolbar definition in the layout XML file

The elements you want to remain visible must be AFTER the toolbar definition in the layout XML file.

Checkout the full code here. The final result is:

Body:
My problem is the next. I would use relatively large texts as CollapsingToolbarLayout title so I need to show it as multiline mode. When I try to change text appearance through the setExpandedTitleTextAppearance() method it doesn't work. The code who I used is the next:

I would like to see the title on multiple lines instead of showing the ellipsis.

ContentLicense: CC BY-SA 4.0


问:
Unexpected performance results comparing INT to BIGINT for IDENTITY columns
I have been asked to perform a performance test using SQL Server 2008. As part of this, I am comparing the speed of IDENTITY columns as PKs using INTs and BIGINTs. I have a simple routine to create 100,000 rows for each type and time the insert speed. The script looks like this:

```<code>SET NOCOUNT ON

CREATE TABLE TestData
(
    PK      INT IDENTITY PRIMARY KEY,
    Dummy   INT
)

DECLARE @Rows   INT
DECLARE @Start  DATETIME

SET @Rows = 100000
SET @Start = GETDATE()

WHILE @Rows > 0
BEGIN
    INSERT INTO TestData (Dummy) VALUES (@Rows)
    SET @Rows = @Rows - 1
END

SELECT @Start, GETDATE(), DATEDIFF(MS, @Start, GETDATE())

DROP TABLE TestData
</code>```

For testing BIGINT identities, I use a very slightly modified version:

```<code>SET NOCOUNT ON

CREATE TABLE TestData
(
    PK      BIGINT IDENTITY PRIMARY KEY,
    Dummy   INT
)

DECLARE @Rows   INT
DECLARE @Start  DATETIME

SET @Rows = 100000
SET @Start = GETDATE()

WHILE @Rows > 0
BEGIN
    INSERT INTO TestData (Dummy) VALUES (@Rows)
    SET @Rows = @Rows - 1
END

SELECT @Start, GETDATE(), DATEDIFF(MS, @Start, GETDATE())

DROP TABLE TestData
</code>```

To my surprise, the BIGINT version runs appreciably faster than the INT version. The INT version on my test kit takes about 30 seconds and the BIGINT about 25 seconds. Granted the test kit has a 64-bit processor. However, it is running 32-bit Windows and 32-bit SQL Server 2008.

Can anyone else recreate, deny, confirm or contest the results or point out if I have missed something?

答:
Server1 - On SQL2005 SP3 64-bit... i just tried it (INT then BIGINT) and got 2.9 and 2.6 secs. Then upping the rows to 500000 i got 15.2 and 15.3 secs.

More 500K INT/BIGINT runs: 14.0/14.6s; 14.0/15.3s; and 14.7/15.3s. So INT is 5.8% faster than BIGINT.

Reversing the order to BIGINT/INT: 15.4/13.8s; 15.3/15.4s; and 12.9/12.7s. INT is 4% faster here.

Server2 - On SQL2000 SP4 EE...

INT/BIGINT: 13.7/10.9s; 10.4/13.9s; 9.9/10.2s. INT is 2.9% faster.

Then switching to BIGINT/INT: 10.2/13.3s; 10.2/10.1s; and 11.2/10.0s. BIGINT is 5.7% faster.

Basically INT is often but not always faster than BIGINT, but not by anything near the variance i'm seeing across runs.

ContentLicense: CC BY-SA 2.5

Body:
I have been asked to perform a performance test using SQL Server 2008. As part of this, I am comparing the speed of IDENTITY columns as PKs using INTs and BIGINTs. I have a simple routine to create 100,000 rows for each type and time the insert speed. The script looks like this:

SET NOCOUNT ON

CREATE TABLE TestData
(
    PK      INT IDENTITY PRIMARY KEY,
    Dummy   INT
)

DECLARE @Rows   INT
DECLARE @Start  DATETIME

SET @Rows = 100000
SET @Start = GETDATE()

WHILE @Rows > 0
BEGIN
    INSERT INTO TestData (Dummy) VALUES (@Rows)
    SET @Rows = @Rows - 1
END

SELECT @Start, GETDATE(), DATEDIFF(MS, @Start, GETDATE())

DROP TABLE TestData

For testing BIGINT identities, I use a very slightly modified version:

SET NOCOUNT ON

CREATE TABLE TestData
(
    PK      BIGINT IDENTITY PRIMARY KEY,
    Dummy   INT
)

DECLARE @Rows   INT
DECLARE @Start  DATETIME

SET @Rows = 100000
SET @Start = GETDATE()

WHILE @Rows > 0
BEGIN
    INSERT INTO TestData (Dummy) VALUES (@Rows)
    SET @Rows = @Rows - 1
END

SELECT @Start, GETDATE(), DATEDIFF(MS, @Start, GETDATE())

DROP TABLE TestData

To my surprise, the BIGINT version runs appreciably faster than the INT version. The INT version on my test kit takes about 30 seconds and the BIGINT about 25 seconds. Granted the test kit has a 64-bit processor. However, it is running 32-bit Windows and 32-bit SQL Server 2008.

Can anyone else recreate, deny, confirm or contest the results or point out if I have missed something?


问:
Ionic: how to programmatically update ion-toggle
this has been bugging me for ages but I can't figure out how to programmatically change an ion-toggle value.

My toggle starts as on. When someone slides it off, I popup a confirmation. If they cancel the confirmation, I want to reset the toggle back to where it was before:

```<code><ion-toggle ng-model="twitterConnection" ng-change="twitterConnectionChange()">Twitter</ion-toggle>

$ionicPopup.confirm({
                title: 'Are you sure?',
                template: 'Are you sure you want to disconnect this account?'
            }).then(function(res) {
                if(res) {
                    delete $window.localStorage.twitterToken;
                    delete $rootScope.user.twitterID;
                }
                else {
                    $scope.twitterConnection = true;
                }
            });
</code>```

I've tried wrapping the $scope.twitterConnection = true; line in $apply, but that gives the "digest already in progress" error. I've tried wrapping it in $timeout, but nothing happens. I'm a relative beginner so all help appreciated, thanks!

EDIT: here's a codepen: http://codepen.io/Shiftlemac/pen/pjZRbP

答:
first update state on your components like $scope.twitterConnection = true; or $scope.twitterConnection = false ; final run $scope.$apply(); finish

sorry my bad english

Body:
this has been bugging me for ages but I can't figure out how to programmatically change an ion-toggle value.

My toggle starts as on. When someone slides it off, I popup a confirmation. If they cancel the confirmation, I want to reset the toggle back to where it was before:

<ion-toggle ng-model="twitterConnection" ng-change="twitterConnectionChange()">Twitter</ion-toggle>

$ionicPopup.confirm({
                title: 'Are you sure?',
                template: 'Are you sure you want to disconnect this account?'
            }).then(function(res) {
                if(res) {
                    delete $window.localStorage.twitterToken;
                    delete $rootScope.user.twitterID;
                }
                else {
                    $scope.twitterConnection = true;
                }
            });

I've tried wrapping the $scope.twitterConnection = true; line in $apply, but that gives the "digest already in progress" error. I've tried wrapping it in $timeout, but nothing happens. I'm a relative beginner so all help appreciated, thanks!

EDIT: here's a codepen: http://codepen.io/Shiftlemac/pen/pjZRbP


问:
Setting TextBox to ReadOnly prevents postback in update panel
My ASP.NET code is as follows:

```<code><script type="text/javascript">
   jQuery(document).ready(function() {
        jQuery("#addScheduleEffectiveStartDate").datepicker({
            minDate: new Date() // Date must be at least today
        })
   })
</script>

<asp:UpdatePanel ID="serviceTypeUpdatePanel" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="addScheduleEffectiveStartDate" EventName="TextChanged" />
        </Triggers>
        <ContentTemplate>
           <asp:TextBox ReadOnly="false" AutoPostBack="true" runat="server" ID="addScheduleEffectiveStartDate" OnTextChanged="addScheduleEffectiveStartDate_TextChanged" />
        </ContentTemplate>
</asp:UpdatePanel>
</code>```

This works as expected - my event handler is called when I change the date (either by typing in the box or by modifying it from the DatePicker).

I'd like to make the Text Box read only though, so that the user can only modify the text box content through the Date Picker. However, when I do that, the event handler is no longer called.

Is there a way to fix that?

答:
I think you'll have to manually fire the postback event yourself after you've updated the textbox value.  You can actually leverage the __doPostBack event just like the TextBox does.

```<code>__doPostBack('addScheduleEffectiveStartDate','')
</code>```

Note that will be the full ClientID used in the doPostBack example above.

Here's a SO post that goes into further detail about invoking a TextChanged event with doPostBack

Body:
My ASP.NET code is as follows:

<asp:UpdatePanel ID="serviceTypeUpdatePanel" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="addScheduleEffectiveStartDate" EventName="TextChanged" />
        </Triggers>
        <ContentTemplate>
           <asp:TextBox ReadOnly="false" AutoPostBack="true" runat="server" ID="addScheduleEffectiveStartDate" OnTextChanged="addScheduleEffectiveStartDate_TextChanged" />
        </ContentTemplate>
</asp:UpdatePanel>

This works as expected - my event handler is called when I change the date (either by typing in the box or by modifying it from the DatePicker).

I'd like to make the Text Box read only though, so that the user can only modify the text box content through the Date Picker. However, when I do that, the event handler is no longer called.

Is there a way to fix that?

Body:
I think you'll have to manually fire the postback event yourself after you've updated the textbox value.  You can actually leverage the __doPostBack event just like the TextBox does.

__doPostBack('addScheduleEffectiveStartDate','')

Note that will be the full ClientID used in the doPostBack example above.

Here's a SO post that goes into further detail about invoking a TextChanged event with doPostBack


问:
How to check if C++ abstract method is defined at runtime
How to check if C++ abstract method is defined at runtime

```<code>class ABase{
public:
 virtual void do1() = 0;
};

class BBase: public ABase{
public:
 virtual void do1(){}
};

class CBase: public ABase{
public:
};

ABase * base = rand() % 2 ? new BBase() : new CBase();
if(&(base->do1) != 0)
  base->do1();
</code>```

This gives error.

Thanks,
Max

答: The compiler won't let you create an instance of a type that doesn't define all abstract methods. In your example above the call to new CBase() will generate a compile time error along the lines of "cannot instantiate abstract type".

Body:
How to check if C++ abstract method is defined at runtime

class ABase{
public:
 virtual void do1() = 0;
};

class BBase: public ABase{
public:
 virtual void do1(){}
};

class CBase: public ABase{
public:
};

ABase * base = rand() % 2 ? new BBase() : new CBase();
if(&(base->do1) != 0)
  base->do1();

This gives error.

Thanks,
Max


问:
How to stop the slider by mouse hover
I am using this code
http://jsfiddle.net/sagive/cAsB3/

my question is how to pause the slider when mouse is on the pictures(hover).

```<code>    $.getJSON('assets/json/slides.json', function(data) {
    $("h2").html(data[0].title);
        $.each(data, function (i, f) {
            if(i>0){
                $("#exampleSlider").append("<li><img src=" + f.content + "/></li>");
            }
        });
   });

$(function () {

/* SET PARAMETERS */
var change_img_time     = 3000;
var transition_speed    =200;

var simple_slideshow    = $("#exampleSlider"),
    listItems           = simple_slideshow.children('li'),
    listLen             = listItems.length,
    i                   = 0,

    changeList = function () {

        listItems.eq(i).fadeOut(transition_speed, function () {
            i += 1;
            if (i === listLen) {
                i = 0;
            }
            listItems.eq(i).fadeIn(transition_speed);
        });
    };
listItems.not(':first').hide();
setInterval(changeList, change_img_time);
});
</code>```

and I have another question also: when I import pic with get JSON. the directory in browser is like this:

```<code>assets/img/pic1.jpg/
</code>```

how can I remove the / at the end of directory. because with / in is not shows the pic in browsers
 thanks

答:
Try:</p>

```<code>if($('#exampleSlider').is(":hover") == true){
    return false;
}
</code>```

Title: How to stop the slider by mouse hover

Body:
I am using this code
http://jsfiddle.net/sagive/cAsB3/

my question is how to pause the slider when mouse is on the pictures(hover).

    $.getJSON('assets/json/slides.json', function(data) {
    $("h2").html(data[0].title);
        $.each(data, function (i, f) {
            if(i>0){
                $("#exampleSlider").append("

");
            }
        });
   });

$(function () {

/* SET PARAMETERS */
var change_img_time     = 3000;
var transition_speed    =200;

var simple_slideshow    = $("#exampleSlider"),
    listItems           = simple_slideshow.children('li'),
    listLen             = listItems.length,
    i                   = 0,

    changeList = function () {

        listItems.eq(i).fadeOut(transition_speed, function () {
            i += 1;
            if (i === listLen) {
                i = 0;
            }
            listItems.eq(i).fadeIn(transition_speed);
        });
    };
listItems.not(':first').hide();
setInterval(changeList, change_img_time);
});

and I have another question also: when I import pic with get JSON. the directory in browser is like this:

assets/img/pic1.jpg/

how can I remove the / at the end of directory. because with / in is not shows the pic in browsers
 thanks

Body:
Try:

if($('#exampleSlider').is(":hover") == true){
    return false;
}


问:
Writing into a text file then reading it back into a textarea javafx
I have made a javafx application that writes an order into a txt file, Then im reading the txt file into a textarea.
My code is working and is printing the file, but i do not know how to format it corectly. Im a noob to javafx, Am I writing it incorrectly? any help is appreciated

This is the main part of the code that writes into the file.

```<code>Date date = new Date( );
      SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");

  BufferedWriter bf = new BufferedWriter(new FileWriter("receipt.txt"));
  bf.write("*************SHERIDAN BAGEL SHOP*************,");
  bf.newLine();
  bf.write(ft.format(date));
  bf.newLine();
  bf.write("Item:\t\t\tQty\tAmount,");
  bf.newLine();
 bf.write("\t\t\t\t-----------");
        bf.newLine();
        bf.write("Pretax Total\t\t\t$"+df.format(cost)+",");
        bf.newLine();
        bf.write("Sales Tax 13%\t\t\t$"+df.format(calctax)+",");
        bf.newLine();
        bf.write("Total Sale\t\t\t$"+df.format(calctotal)+",");
        bf.newLine();
        bf.write("*********THANK YOU FOR YOUR ORDER*********,");

      bf.close();
</code>```

This is the output in the textfile

```<code>*************SHERIDAN BAGEL SHOP*************,
Sat 2017.04.01 at 01:06:57 PM EDT
Item:           Qty     Amount,
                      -----------
Pretax Total            $0.00,
Sales Tax 13%           $0.00,
Total Sale              $0.00,
*********THANK YOU FOR YOUR ORDER*********,
</code>```

This is the code that reads the file

```<code>@FXML
    private TextArea receipt;

 public void ViewReceipt() {
     try {
        Scanner s = new Scanner(new File("receipt.txt"));
        while (s.hasNext()) {
          receipt.appendText(s.nextLine()+"\n");
        }
    } catch (FileNotFoundException ex) {
        System.err.println(ex);
    }

}
</code>```

This is how it is in the textarea

```<code>*************SHERIDAN BAGEL SHOP*************,
Sat 2017.04.01 at 01:06:57 PM EDT
Item:           Qty Amount,
                -----------
Pretax Total            $0.00,
Sales Tax 13%           $0.00,
Total Sale          $0.00,
*********THANK YOU FOR YOUR ORDER*********,
</code>```

答:
You can play with this. If all the receipts are going to look very similar.

```<code>import java.io.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;
import javafx.application.*;
import javafx.event.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;

/**
 *
 * @author Sedrick
 */
public class JavaFXApplication22 extends Application {

    TextArea textArea;

    @Override
    public void start(Stage primaryStage)
    {
        textArea = new TextArea();

        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event)
            {
                Date date = new Date();
                SimpleDateFormat ft = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
                String pattern = "$###,###.###";
                DecimalFormat df = new DecimalFormat(pattern);

                try (BufferedWriter bf = new BufferedWriter(new FileWriter("receipt.txt")))
                {
                    bf.write("*************SHERIDAN BAGEL SHOP*************,");
                    bf.newLine();
                    bf.write(ft.format(date));
                    bf.newLine();
                    bf.write(writeSpace(25, "Item:") + writeSpace(12, "Qty") + "Amount,");
                    bf.newLine();
                    bf.write(writeSpace(35, "") + "-----------");
                    bf.newLine();
                    bf.write(writeSpace(35, "Pretax Total") + df.format(100.0) + ",");
                    bf.newLine();
                    bf.write(writeSpace(35, "Sales Tax 13%") + df.format(10000.0) + ",");
                    bf.newLine();
                    bf.write(writeSpace(35, "Total Sale") + df.format(10.0) + ",");
                    bf.newLine();
                    bf.write("*********THANK YOU FOR YOUR ORDER*********,");
                }
                catch (IOException ex)
                {
                    Logger.getLogger(JavaFXApplication22.class.getName()).log(Level.SEVERE, null, ex);
                }

                ViewReceipt();
            }
        });

        VBox root = new VBox();
        root.getChildren().addAll(textArea, btn);

        Scene scene = new Scene(root, 500, 500);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public void ViewReceipt()
    {
        try
        {
            Scanner s = new Scanner(new File("receipt.txt"));
            while (s.hasNext())
            {
                String line = s.nextLine();
                if (line.contains("$"))
                {
                    String[] splitLine = line.split("\\s+");
                    for (String entry : splitLine)
                    {
                        if (entry.contains("$"))
                        {
                            textArea.appendText("\t\t\t\t " + entry + "\n");
                        }
                        else
                        {
                            textArea.appendText(entry + " ");
                        }
                    }
                }
                else if (line.contains("-"))
                {
                    textArea.appendText("\t\t\t\t\t\t" + line.trim() + "\n");
                    System.out.println(line);
                }
                else if (line.contains("Amount"))
                {
                    String[] splitLine = line.split("\\s+");
                    textArea.appendText(splitLine[0] + "\t\t\t" + splitLine[1] + "\t\t" + splitLine[2] + "\n");
                }
                else
                {

                    textArea.appendText(line + "\n");
                }
            }
        }
        catch (FileNotFoundException ex)
        {
            System.err.println(ex);
        }
    }

    public String writeSpace(int length, String string)
    {
        String spaces = "";

        for (int i = 0; i < length - string.length(); i++)
        {
            spaces += " ";
        }

        System.out.println(string.length() + spaces.length());
        return string + spaces;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        launch(args);
    }

}
</code>```

Updated code!

Body:
I have made a javafx application that writes an order into a txt file, Then im reading the txt file into a textarea.
My code is working and is printing the file, but i do not know how to format it corectly. Im a noob to javafx, Am I writing it incorrectly? any help is appreciated

This is the main part of the code that writes into the file.

Date date = new Date( );
      SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");

  BufferedWriter bf = new BufferedWriter(new FileWriter("receipt.txt"));
  bf.write("*************SHERIDAN BAGEL SHOP*************,");
  bf.newLine();
  bf.write(ft.format(date));
  bf.newLine();
  bf.write("Item:\t\t\tQty\tAmount,");
  bf.newLine();
 bf.write("\t\t\t\t-----------");
        bf.newLine();
        bf.write("Pretax Total\t\t\t$"+df.format(cost)+",");
        bf.newLine();
        bf.write("Sales Tax 13%\t\t\t$"+df.format(calctax)+",");
        bf.newLine();
        bf.write("Total Sale\t\t\t$"+df.format(calctotal)+",");
        bf.newLine();
        bf.write("*********THANK YOU FOR YOUR ORDER*********,");

      bf.close();

This is the output in the textfile

*************SHERIDAN BAGEL SHOP*************,
Sat 2017.04.01 at 01:06:57 PM EDT
Item:           Qty     Amount,
                      -----------
Pretax Total            $0.00,
Sales Tax 13%           $0.00,
Total Sale              $0.00,
*********THANK YOU FOR YOUR ORDER*********,

This is the code that reads the file

@FXML
    private TextArea receipt;

 public void ViewReceipt() {
     try {
        Scanner s = new Scanner(new File("receipt.txt"));
        while (s.hasNext()) {
          receipt.appendText(s.nextLine()+"\n");
        }
    } catch (FileNotFoundException ex) {
        System.err.println(ex);
    }

}

This is how it is in the textarea

*************SHERIDAN BAGEL SHOP*************,
Sat 2017.04.01 at 01:06:57 PM EDT
Item:           Qty Amount,
                -----------
Pretax Total            $0.00,
Sales Tax 13%           $0.00,
Total Sale          $0.00,
*********THANK YOU FOR YOUR ORDER*********,

Body:
You can play with this. If all the receipts are going to look very similar.

import java.io.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;
import javafx.application.*;
import javafx.event.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;

/**
 *
 * @author Sedrick
 */
public class JavaFXApplication22 extends Application {

    TextArea textArea;

    @Override
    public void start(Stage primaryStage)
    {
        textArea = new TextArea();

        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event)
            {
                Date date = new Date();
                SimpleDateFormat ft = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
                String pattern = "$###,###.###";
                DecimalFormat df = new DecimalFormat(pattern);

                try (BufferedWriter bf = new BufferedWriter(new FileWriter("receipt.txt")))
                {
                    bf.write("*************SHERIDAN BAGEL SHOP*************,");
                    bf.newLine();
                    bf.write(ft.format(date));
                    bf.newLine();
                    bf.write(writeSpace(25, "Item:") + writeSpace(12, "Qty") + "Amount,");
                    bf.newLine();
                    bf.write(writeSpace(35, "") + "-----------");
                    bf.newLine();
                    bf.write(writeSpace(35, "Pretax Total") + df.format(100.0) + ",");
                    bf.newLine();
                    bf.write(writeSpace(35, "Sales Tax 13%") + df.format(10000.0) + ",");
                    bf.newLine();
                    bf.write(writeSpace(35, "Total Sale") + df.format(10.0) + ",");
                    bf.newLine();
                    bf.write("*********THANK YOU FOR YOUR ORDER*********,");
                }
                catch (IOException ex)
                {
                    Logger.getLogger(JavaFXApplication22.class.getName()).log(Level.SEVERE, null, ex);
                }

                ViewReceipt();
            }
        });

        VBox root = new VBox();
        root.getChildren().addAll(textArea, btn);

        Scene scene = new Scene(root, 500, 500);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public void ViewReceipt()
    {
        try
        {
            Scanner s = new Scanner(new File("receipt.txt"));
            while (s.hasNext())
            {
                String line = s.nextLine();
                if (line.contains("$"))
                {
                    String[] splitLine = line.split("\\s+");
                    for (String entry : splitLine)
                    {
                        if (entry.contains("$"))
                        {
                            textArea.appendText("\t\t\t\t " + entry + "\n");
                        }
                        else
                        {
                            textArea.appendText(entry + " ");
                        }
                    }
                }
                else if (line.contains("-"))
                {
                    textArea.appendText("\t\t\t\t\t\t" + line.trim() + "\n");
                    System.out.println(line);
                }
                else if (line.contains("Amount"))
                {
                    String[] splitLine = line.split("\\s+");
                    textArea.appendText(splitLine[0] + "\t\t\t" + splitLine[1] + "\t\t" + splitLine[2] + "\n");
                }
                else
                {

                    textArea.appendText(line + "\n");
                }
            }
        }
        catch (FileNotFoundException ex)
        {
            System.err.println(ex);
        }
    }

    public String writeSpace(int length, String string)
    {
        String spaces = "";

        for (int i = 0; i < length - string.length(); i++)
        {
            spaces += " ";
        }

        System.out.println(string.length() + spaces.length());
        return string + spaces;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        launch(args);
    }

}

Updated code!


问:
Random.choice not working correctly python
I have the following code for example:

```<code>n = ['321','243','780']
b = ['12','56','90']
a = ['178', '765', '111']

E = input('Enter Word...')
qw = 1
Code = ('')
E_ready = [E[no:no+qw] for no in range(0, len(E), qw)]
for code in E_Ready:
   letter = random.choice(code)
   Code += letter
</code>```

If you enter the word 'nba' then it will output as 'nba', I want it to output with random elements from each letter's respective list so for example '32112178'

答:
I agree with the comment, it is better to use something like:

```<code>d = {'n':[mylist]}
letter = random.choice(d['n'])
</code>```

the problem is that random.choice works on strings too... it simply considers them to be a list of characters. in your case the code variable and n are supposed to be exactly the same but are in fact not. You could also do

```<code>n = [list]
code = n ## only makes any sense, if there
         ## is a procedure assigns it based on some condition
letter = random.choice(code)
</code>```

Body:
I have the following code for example:

n = ['321','243','780']
b = ['12','56','90']
a = ['178', '765', '111']

E = input('Enter Word...')
qw = 1
Code = ('')
E_ready = [E[no:no+qw] for no in range(0, len(E), qw)]
for code in E_Ready:
   letter = random.choice(code)
   Code += letter

If you enter the word 'nba' then it will output as 'nba', I want it to output with random elements from each letter's respective list so for example '32112178'

Body:
I agree with the comment, it is better to use something like:

d = {'n':[mylist]}
letter = random.choice(d['n'])

the problem is that random.choice works on strings too... it simply considers them to be a list of characters. in your case the code variable and n are supposed to be exactly the same but are in fact not. You could also do

n = [list]
code = n ## only makes any sense, if there
         ## is a procedure assigns it based on some condition
letter = random.choice(code)


答:
As Willem van Onsem correctly mentioned in the comments:

"...that is really bad design, call-by-name is rather unsafe. You better use a dictionary."

So, try this:

```<code>n = {'option1':'321','option2':'243','option3':'780'}
letter = random.choice(list(n.values()))
</code>```

Or, shorter, as Chris has mentioned:

```<code>d = {'n':[321, 243, 780]}
letter = random.choice(d['n'])
</code>```

Results from print(letter) (on both options):

```<code>321
321
780
243
etc..
</code>```

EDIT:

How to add extra variables:

```<code>n = 'n'
d = {n:[321, 243, 780]}
letter = random.choice(d[n])
q = 'q'
d[q] = [600, 234, 180]
new_letter = random.choice(d[q])
</code>```

Now print(new_letter) gives:

```<code>234
180
180
600
etc..
</code>```

SECOND EDIT (which btw is pure bonus since the question turned into a completely different one then first asked.. therefor, it is left unoptimized. Yet, working nonetheless..):

```<code>import random
d = {'n':[321, 243, 780], 'b':['12','56','90'], 'a':['178', '765', '111']}

E = input('Enter Word...')

inputword = list(E)

for key in d.keys():
    if key in inputword:
        for i in range(len(inputword)):
            if inputword[i] == key:
                try:
                    inputword[i] = str(random.choice(d[key]))
                except:
                    pass

result = ''.join(inputword)
print(result)
</code>```

If input = nba then output = 32190111

If input = nhhsygbbvvra then output = 321hhsyg5690vvr178

Etc..

Title: Random.choice not working correctly python

Body:
As Willem van Onsem correctly mentioned in the comments:

"...that is really bad design, call-by-name is rather unsafe. You better use a dictionary."

So, try this:

n = {'option1':'321','option2':'243','option3':'780'}
letter = random.choice(list(n.values()))

Or, shorter, as Chris has mentioned:

d = {'n':[321, 243, 780]}
letter = random.choice(d['n'])

Results from print(letter) (on both options):

321
321
780
243
etc..

EDIT:

How to add extra variables:

n = 'n'
d = {n:[321, 243, 780]}
letter = random.choice(d[n])
q = 'q'
d[q] = [600, 234, 180]
new_letter = random.choice(d[q])

Now print(new_letter) gives:

234
180
180
600
etc..

SECOND EDIT (which btw is pure bonus since the question turned into a completely different one then first asked.. therefor, it is left unoptimized. Yet, working nonetheless..):

import random
d = {'n':[321, 243, 780], 'b':['12','56','90'], 'a':['178', '765', '111']}

E = input('Enter Word...')

inputword = list(E)

for key in d.keys():
    if key in inputword:
        for i in range(len(inputword)):
            if inputword[i] == key:
                try:
                    inputword[i] = str(random.choice(d[key]))
                except:
                    pass

result = ''.join(inputword)
print(result)

If input = nba then output = 32190111

If input = nhhsygbbvvra then output = 321hhsyg5690vvr178

Etc..


问:
Why is the variable name replaced by its value causing " 'xxx' should be declared" error?
I wrote the following PL/SQL block:

```<code>declare
    v_name varchar2(20);
    v_sal integer;
begin
    EXECUTE IMMEDIATE ('CREATE TABLE EMP5 (name varchar2(20),sal integer,primary key(name))');
    dbms_output.put_line('Enter name : ');
    v_name:=&v_name;
    dbms_output.put_line('salary : ');
    v_sal :=&v_sal;
    insert into emp5 (name,sal) values (v_name,v_sal);
end;
/
</code>```

And then I got the following compiler output:

```<code>Enter a valeur for v_name : dhia
old 6 : v_name:=&v_name;
new 6 : v_name:=dhia;
Enter a valeur for v_sal : 10
old 8 : v_sal :=v_&sal;
new 8 : v_sal :=10;
v_name:=dhia;
      *
ERREUR at line 6 :
ORA-06550: line 6, colon 7 :
PLS-00201: the identifier 'DHIA' should be declared
ORA-06550: line 6, colon 1 :
PL/SQL: Statement ignored
ORA-06550: line9, colon 13 :
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 9, colon 1 :
PL/SQL: SQL Statement ignored
</code>```

My question is why the variable 'name' replaced by its value 'dhia' in the script causing that error, and how to fix it?

答:
You should not use your variables this way, the expected behavior is to replace them by its values, your variables should not be the same as your columns names, please try the following:</p>

```<code>declare
varName varchar2(20);
varSal integer;
sql_stmt varchar2(200);
begin
EXECUTE IMMEDIATE ('CREATE TABLE EMP5 (name varchar2(20),sal integer,primary key(name))');
dbms_output.put_line('Enter name : ');
varName :=&varName;
dbms_output.put_line('salary : ');
varSal :=&varSal;
sql_stmt := 'INSERT INTO EMP5 VALUES (:1, :2)';
EXECUTE IMMEDIATE sql_stmt USING varName, varSal;
end;
/
</code>```

Body:
I wrote the following PL/SQL block:

declare
    v_name varchar2(20);
    v_sal integer;
begin
    EXECUTE IMMEDIATE ('CREATE TABLE EMP5 (name varchar2(20),sal integer,primary key(name))');
    dbms_output.put_line('Enter name : ');
    v_name:=&v_name;
    dbms_output.put_line('salary : ');
    v_sal :=&v_sal;
    insert into emp5 (name,sal) values (v_name,v_sal);
end;
/

And then I got the following compiler output:

Enter a valeur for v_name : dhia
old 6 : v_name:=&v_name;
new 6 : v_name:=dhia;
Enter a valeur for v_sal : 10
old 8 : v_sal :=v_&sal;
new 8 : v_sal :=10;
v_name:=dhia;
      *
ERREUR at line 6 :
ORA-06550: line 6, colon 7 :
PLS-00201: the identifier 'DHIA' should be declared
ORA-06550: line 6, colon 1 :
PL/SQL: Statement ignored
ORA-06550: line9, colon 13 :
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 9, colon 1 :
PL/SQL: SQL Statement ignored

My question is why the variable 'name' replaced by its value 'dhia' in the script causing that error, and how to fix it?

Body:
You should not use your variables this way, the expected behavior is to replace them by its values, your variables should not be the same as your columns names, please try the following:

declare
varName varchar2(20);
varSal integer;
sql_stmt varchar2(200);
begin
EXECUTE IMMEDIATE ('CREATE TABLE EMP5 (name varchar2(20),sal integer,primary key(name))');
dbms_output.put_line('Enter name : ');
varName :=&varName;
dbms_output.put_line('salary : ');
varSal :=&varSal;
sql_stmt := 'INSERT INTO EMP5 VALUES (:1, :2)';
EXECUTE IMMEDIATE sql_stmt USING varName, varSal;
end;
/