How to call update Stored Procedure from .Net Core Entity Framework Posted: 15 Feb 2022 08:56 AM PST Please find the Stored Procedure below CREATE PROCEDURE [dbo].[Admin_SetUserToIsDeleted] (@bb_customer_id int) AS declare @bb_customer_id_local INT SET @bb_customer_id_local = @bb_customer_id BEGIN TRAN UPDATE dbo.bb_customer_login_identification WITH (rowlock) SET is_deleted = 1 WHERE bb_customer_id = @bb_customer_id_local UPDATE dbo.bb_customer SET is_deleted = 1 WHERE bb_customer_id = @bb_customer_id_local COMMIT TRAN GO |
Subsetting list of lists by keeping the list format Posted: 15 Feb 2022 08:56 AM PST Assume I have a list of lists as bellow. I want to keep the second and fourth element of each list, IN a format of a list. Basically, I want to do what rapply(eig_inter_list, function(x) x[c(2,4)]) does but keep the elements of each list within the list itself. The output would be a list of lists but in each list I would have the second and fourth element, instead of all 57. This is a sample of what my data looks like. dput(eig_inter_list[c(1,2,3)]) list(structure(c(0.314642768055768, 0.325549276750512, 0.32407558151974, 0.503037906331374, 0.177702652110427, 0.649874624573978, 0.22304809425227, 0.19744998358554, 0.322951763103893, 0.417206897701431, 0.378171649699382, 0.25116873932351, 0.485979263395877, 0.411851682123569, 1, 0.478943307151144, 0.710983939873711, 0.205890770051514, 0.335737092407451, 0.495130707288105, 0.395609776015166, 0.367388748844004, 0.236987996918897, 0.17727518450146, 0.542503233906977, 0.22322071021728, 0.305512801458551, 0.703463566780157, 0.0565731620746889, 0.281865665377428, 0.34675705775566, 0.240102820697777, 0.847955796670962, 0.467145199252136, 0.408110899113892, 0.121168347150886, 0.166279979571487, 0.225178903127632, 0.836003339903779, 0.298624839828843, 0.156832369183448, 0.331724029229045, 0.28607359410209, 0.438251331553188, 0.531970745173967, 0.473559658632999, 0.339927590064139, 0.329554185654697, 0.23010077174135, 0.444399306655095, 0.265064970418036, 0.54141477127972, 0.181034728719507, 0.217971681487819, 0.702604336646787, 0.260277784525433, 0.9313793258404), .Dim = c(57L, 1L)), structure(c(0.758053727134031, 0.389169917077854, 0.553155900977713, 0.680957693695371, 0.688478238016961, 0.5406614343729, 0.654085903776063, 0.249245017029272, 0.527924916117291, 0.607686315557293, 0.328402935290058, 0.472653172631753, 0.503447923078263, 0.540956133924371, 0.367957509649887, 0.537869789262281, 0.177185397396901, 0.49323257867289, 0.380042131111929, 0.76085241271694, 0.540174821432495, 0.283063101888133, 0.319997654939547, 0.651366853994039, 0.706918785162937, 0.578280317866076, 0.871853266130338, 0.874076858150783, 1, 0.611669207162514, 0.28036164071929, 0.292694661837052, 0.610126478002428, 0.380386438921713, 0.669982812090512, 0.122065848180652, 0.974400986291088, 0.945135694392546, 0.462456530300744, 0.134501132230783, 0.322784038090134, 0.317780702999941, 0.662847059747895, 0.523285813371882, 0.668825630786058, 0.79637143229052, 0.379229953581731, 0.282559418794954, 0.745322058370275, 0.697765403065504, 0.282171232377215, 0.672824204974444, 0.812732702343435, 0.747236048953355, 0.810360825374334, 0.147736041262474, 0.638551018944304), .Dim = c(57L, 1L)), structure(c(0.580650487050986, 0.226493031789664, 0.216153469107205, 0.679582322890881, 0.585765696317977, 0.277602052620714, 0.301697850942933, 0.539494048925467, 0.22052504674914, 0.279450501649262, 0.292210734005604, 0.406706750636561, 0.253178327897084, 0.26902431345799, 0.72080329402394, 0.538483400997092, 0.132513153071638, 0.169267787671607, 0.355070307460915, 0.420987061713029, 0.355905556319682, 0.423354094728718, 0.225064747308464, 0.368813823547299, 0.290838727568061, 0.191959913771819, 0.412085260195494, 0.220140351021593, 0.251950925564949, 0.360732509927935, 0.130353223587661, 0.355856853738614, 0.399558273021718, 0.351244298106977, 0.280432050072677, 0.51121978973842, 0.300682631494935, 0.39923136729231, 0.217749058297645, 0.347719424129099, 0.28916475155952, 0.531747942212439, 0.384583756749702, 0.19911455191363, 0.574044809883757, 0.206919558647874, 1, 0.327370421244658, 0.561049901898945, 0.177575568867026, 0.311627824832627, 0.214432911950344, 0.405893310593152, 0.328365875498285, 0.403268555194588, 0.21904514354561, 0.243848932866513), .Dim = c(57L, 1L))) |
Configure Code Analysis/Ruleset as default in Visual Studio versus at a project level Posted: 15 Feb 2022 08:56 AM PST Is there a way to configure Code Analysis (FXCop/Roslyn) at a Visual Studio level versus at each project level? What I am looking for is for any developer creating a new Visual Studio solution for their next project by default have the rules enabled and not forcing each developer to manually enable the rule for each solution/project. This would be for Visual Studio 2019 |
Connecting MS Access database to Bigquery Using ODBC Posted: 15 Feb 2022 08:56 AM PST When i tried to connect with bigquery using OAuth Mechanism as "user Authentication" we are facing below error getting Refresh token DSN configuration Error. (1120) SSL verification failed because the server host name specified for the connection does not match the "CN" entry in the "Subject" field or any of the "DNS Name" entries of the "Subject Alternative Name" field in the server certificate We cannot get catalog and dataset information from the dropdown. |
Flutter image_picker crash only in the Play Store Live version Posted: 15 Feb 2022 08:56 AM PST There is an app where we use image_picker(0.8.3) and wechat_assets_picker(^6.3.1) together. It works fine on emulator and normal device. When we get the release apk, it works smoothly on the devices we installed it on. However, in the same version that we bought bundle and uploaded to the store, when the image_picker structure works in live (camera or gallery), the app crashes in the background. We are using the new versions of both packages. 0.8.3 There is no error on the iOS side. We don't know if it's causing a problem when generating google bundle as both packages access the gallery. We don't know if it will continue without any problems if we put it on google play as an apk. (we will try this) we only have logs where we get the Abort error ( sentry and crashlytic ) without details ... |
How to exactly invoke a function by using a member function pointer(and generics)? Posted: 15 Feb 2022 08:56 AM PST Im having troubles invoking a function by using function pointer declared as a member of a struct inside of a class In the main function: int main() { int size = 4; Bus prova; int su = (prova.BIOS_ROM.*read_ptr)(prova.BIOS_ROM, size); } in the header file(which contains the definition of the struct): template <typename T> // T is the bit width of the bus struct bus_t { T bitfield; char r_perm : 3; // 8/16/32 bit read char w_perm : 3; // 8/16/32 bit read T (Bus::*read_ptr)(struct bus_t<T> bus, int size); void (Bus::*write_ptr)(struct bus_t<T> bus, int size, T data); }; template <typename T> T read(struct bus_t<T> bus, int size); template <typename T> void write(struct bus_t<T> bus, int size, T data); struct bus_t<uint32_t> BIOS_ROM; ... #include "bus.tpp" and the implementations of the read/write methods are included in the tpp file: template <typename T> T Bus::read(struct bus_t<T> bus, int size){/*code*/} template <typename T> void Bus::write(struct bus_t<T> bus, int size, T data){/*code*/} and in the bus.cpp file I have the initialization of the function pointer inside the class constructor: Bus::Bus() { BIOS_ROM.read_ptr = &Bus::read<uint32_t>; BIOS_ROM.write_ptr = &Bus::write<uint32_t>; } I really cant find where the problem lies. Im new to C++(Ive been mostly programming in java/c) so I dont exactly know how generics syntax work in C++ I've also tried taking a look at this thread Why can templates only be implemented in the header file? but I didnt actually understand what should I fix in my code in order to make it run |
How to host dotnet core API in nginx server on windows Posted: 15 Feb 2022 08:55 AM PST I want to host my dot net core web API on the nginx windows machine. Please any one can help on this . |
SPLIT_BUNDLE 9: Posted: 15 Feb 2022 08:55 AM PST |
Use do.call to run a function with a given list of parameters by the end user Posted: 15 Feb 2022 08:55 AM PST I have a function called tidy_normal() from TidyDensity package. This takes in exactly one parameter per arguement, example: .mean = 1 What I want to do is build a function that will take in a quoted string from a user and the parameter list like so: tidy_multi_dist( .tidy_dist = "tidy_normal", .param_list = list( .n = 50, .mean = c(-1, 0, 1), .sd = 1, .num_sims = 1) ) What I have so far is: tidy_multi_dist <- function( .tidy_dist = NULL, .param_list = list() ) { # Check param ---- if (is.null(.tidy_dist)) { rlang::abort( "Please enter a 'tidy_' distribution function like 'tidy_normal' in quotes." ) } if (length(.param_list) == 0) { rlang::abort( "Please enter some parameters for your chosen 'tidy_' distribution." ) } # Call used --- td <- as.character(.tidy_dist) # Params ---- params <- .param_list # Params for the call ---- n <- as.integer(params$.n) num_sims <- as.integer(params$.num_sims) x <- seq(1, num_sims, 1) # Final parameter list final_params_list <- params[which(!names(params) %in% c(".n", ".num_sims"))] # Set the grid to make the calls ---- param_grid <- expand.grid(final_params_list) df <- tidyr::expand_grid( n = n, param_grid, sim = as.integer(x) ) #%>% #group_by_all() func_parm_list <- as.list(df) # Run call on the grouped df ---- dff <- df %>% dplyr::rowwise() %>% dplyr::mutate(results = list(do.call(td, func_parm_list))) # fails here #df %>% rowwise() %>% mutate(results = list(do.call(td, list(.n = n, .num_sims = num_sims,.mean = .mean, .sd = .sd)))) %>% unnest(results) # Get the attributes to be used later on ---- atb <- dff$results[[1]] %>% attributes() # Make Dist Type for column ---- dist_type <- stringr::str_remove(atb$tibble_type, "tidy_") %>% stringr::str_replace_all(pattern = "_", " ") %>% stringr::str_to_title() # Get column names from the param_grid in order to make teh dist_type column ---- cols <- names(param_grid) dff$dist_name <- paste0( paste0(dist_type, " c("), apply(dff[, cols], 1, paste0, collapse = ", "), ")" ) df_unnested_tbl <- dff %>% tidyr::unnest(results) %>% dplyr::ungroup() %>% dplyr::select(sim_number, dist_name, x:q) %>% dplyr::mutate(dist_name = as.factor(dist_name)) %>% dplyr::arrange(sim_number, dist_name) # Attach attributes ---- attr(df_unnested_tbl, "all") <- atb attr(df_unnested_tbl, "tbl") <- "tidy_multi_tibble" # Return ---- return(df_unnested_tbl) } The error message I am getting is: > df %>% + #dplyr::rowwise() %>% + dplyr::mutate(results = list(do.call(td, func_parm_list))) Error in `dplyr::mutate()`: ! Problem while computing `results = list(do.call(td, func_parm_list))`. i The error occurred in group 1: n = 500, .mean = -1, .sd = 1, sim = 1. Caused by error in `tidy_normal()`: ! unused arguments (n = c(500, 500, 500), sim = c(1, 1, 1)) Run `rlang::last_error()` to see where the error occurred. Since I do not know what distribution the user is going to enter I wanted this function to be dynamic and use do.call instead of making an explicit rlang::call2 for each possibility. I am not sure how to proceed from here as everything is failing, I assume because my do.call is wrong. |
Repeat a input variable Posted: 15 Feb 2022 08:56 AM PST I'm working on my AP create task. I made a shopping cart where if you type "shop" in the code, a prompt pops up that allows you to add a item to cart. Code: def shop(): if user_1 == "shop": print("\n") shop_1 = input("type a item to add to cart") shopping_list.append(shop_1) Right now, it works so that when you enter an item and press enter, it basically stops the code. How would I make it so it repeats and u can keep typing variables to add to the list? |
How to set discord title in Discord Webhooks? Posted: 15 Feb 2022 08:55 AM PST I use Discord Webhooks and I don't find how to set in title embed message link ([name here](https://linkhere.xd) doesn't work). |
How to update firebase without changing syntax Posted: 15 Feb 2022 08:56 AM PST I have no idea how to do this, but unfortunately the project ive been working on is running off of firebase 7.14.0, as a newer developer I have found this to be very tough to work with because there is no documentation. Is there anyway I can move to firebase 9 without having to change all of the syntax? |
How do I play a Soundfile.wav through my microphone output? Posted: 15 Feb 2022 08:55 AM PST Do you know "Marcophono" where you press different buttons and a crazy italian guy speaks different phrases on button presses to make fun of the other person on the phone? I need such a function for work to play a certain sentence in a music file every time on the push of a button through my microphone, so that my counterpart hears it. Can someone help me with the code snippet on how to call a file via a button? I already have the button function, it's just a matter of playing it over the microphone. JFrame frame = new JFrame(); JButton button = new JButton("Say my name"); File sayMyName = new File("C:\\Users\\XX\\Desktop\\XX\\Java\\XXX.wav"); @Override public void actionPerformed(ActionEvent e) { // Get XXX.wav here and play it through my microphone } |
Converting a string to a file object so i can run a function inside of it. Python Posted: 15 Feb 2022 08:55 AM PST import test functions = [test.run] functions[0]() which returns 'yay' This is what i have tried and it works but i want to use the name string variable as the method of running the function so something like this: import test name = 'test' functions = [name + '.run'] functions[0]() which errors 'AttributeError: 'str' object has no attribute 'run' but a string dosent have an attribute to run. How would i convert this string or make it be usable like i had it in the first example. (the second file just has this): def run(): print("yay") |
Pandas groupby() different output with versions 0.23.4 and 1.3.4 Posted: 15 Feb 2022 08:55 AM PST I have 2 codebases with the same code, the only difference is the version of pandas being used: - OLD environment uses pandas version 0.23.4
- NEW environment uses pandas version 1.3.4
I have debugged my code up to this line of code, after which the result is different: result = df.groupby(group_items, as_index=as_index, sort=sort)[sum_items].sum() Variables df , group_items , as_index , sort and sum_items are all exactly the same between both NEW and OLD environments. However, the returned result is a little bit different in the NEW version. Specifically, the output looks like this: NEW environment: df.groupby(group_items, as_index=as_index, sort=sort)[sum_items].sum() SST_ADJ_TYPE SST_ADJ_RULE ... NCI AMOUNT 0 0 SST22a,SST22b, ... 1874757.0 1 0 SST22a,SST22b, ... 5945263.0 2 0 SST22a,SST22b, ... 4303110.0 3 0 SST22a,SST22b, ... 5342991.0 4 0 SST22a,SST22b, ... 9245478.0 ... ... ... ... .. ... 133674 3 SST22b,SST07, ... 4164305.0 133675 3 SST22b,SST07, ... 7280203.0 133676 3 SST22b,SST07, ... 1235752.0 133677 3 SST22b,SST07, ... 3115825.0 133678 3 SST22b,SST07, ... 1436891.0 [133679 rows x 16 columns] OLD environment: df.groupby(group_items, as_index=as_index, sort=sort)[sum_items].sum() SST_ADJ_TYPE SST_ADJ_RULE ... NCI AMOUNT 0 0 SST22a,SST22b, ... 1874757.0 1 0 SST22a,SST22b, ... 5945263.0 2 0 SST22a,SST22b, ... 4303110.0 3 0 SST22a,SST22b, ... 5342991.0 4 0 SST22a,SST22b, ... 9245478.0 5 0 SST22a,SST22b, ... 4016202.0 6 0 SST22a,SST22b, ... 8799969.0 7 0 SST22a,SST22b, ... 1503269.0 8 0 SST22a,SST22b, ... 6385991.0 9 0 SST22a,SST22b, ... 1686520.0 10 0 SST22a,SST22b, ... 5287114.0 11 0 SST22a,SST22b, ... 2648534.0 12 0 SST22a,SST22b, ... 6159017.0 13 0 SST22a,SST22b, ... 5959591.0 14 0 SST22a,SST22b, ... 5809998.0 15 0 SST22a,SST22b, ... 4929077.0 16 0 SST22a,SST22b, ... 9166004.0 17 0 SST22a,SST22b, ... 2124498.0 18 0 SST22a,SST22b, ... 3051659.0 19 0 SST22a,SST22b, ... 1859001.0 20 0 SST22a,SST22b, ... 8522834.0 21 0 SST22a,SST22b, ... 7803526.0 22 0 SST22a,SST22b, ... 4067546.0 23 0 SST22a,SST22b, ... 9218486.0 24 0 SST22a,SST22b, ... 1453153.0 25 0 SST22a,SST22b, ... 7411706.0 26 0 SST22a,SST22b, ... 9160444.0 27 0 SST22a,SST22b, ... 6255426.0 28 0 SST22a,SST22b, ... 6007841.0 29 0 SST22a,SST22b, ... 4744588.0 ... ... ... ... .. ... 133649 3 SST22b,SST07, ... 6487572.0 133650 3 SST22b,SST07, ... 3593805.0 133651 3 SST22b,SST07, ... 9192954.0 133652 3 SST22b,SST07, ... 2394981.0 133653 3 SST22b,SST07, ... 9398971.0 133654 3 SST22b,SST07, ... 5536294.0 133655 3 SST22b,SST07, ... 8759613.0 133656 3 SST22b,SST07, ... 2012212.0 133657 3 SST22b,SST07, ... 7930551.0 133658 3 SST22b,SST07, ... 3407871.0 133659 3 SST22b,SST07, ... 3071541.0 133660 3 SST22b,SST07, ... 1863129.0 133661 3 SST22b,SST07, ... 8439646.0 133662 3 SST22b,SST07, ... 1518097.0 133663 3 SST22b,SST07, ... 7396702.0 133664 3 SST22b,SST07, ... 8470274.0 133665 3 SST22b,SST07, ... 8363095.0 133666 3 SST22b,SST07, ... 1115614.0 133667 3 SST22b,SST07, ... 6317772.0 133668 3 SST22b,SST07, ... 2645613.0 133669 3 SST22b,SST07, ... 6555039.0 133670 3 SST22b,SST07, ... 5274987.0 133671 3 SST22b,SST07, ... 5779789.0 133672 3 SST22b,SST07, ... 6974948.0 133673 3 SST22b,SST07, ... 6370779.0 133674 3 SST22b,SST07, ... 4164305.0 133675 3 SST22b,SST07, ... 7280203.0 133676 3 SST22b,SST07, ... 1235752.0 133677 3 SST22b,SST07, ... 1436891.0 133678 3 SST22b,SST07, ... 3115825.0 [133679 rows x 16 columns] As you can see, the amount of rows and columns is the same. The columns are also exactly the same between the two result s. However, when you check the AMOUNT column, you see that, for example in the last rows, the result from the NEW environment has the values combined (last row swapped for the previous row, for example). Any ideas why is this happening? PS: Unfortunately, I can not provide a DataFrame which you can load since the DataFrame I'm using has lots of data in it. I'm more of looking to a theoretical answer on what changed between the above mentioned versions of pandas and/or which argument to use in the NEW environment to have the exact same result as in the OLD environment. |
MongoDB Data Range Filter Subcollection Posted: 15 Feb 2022 08:56 AM PST I am trying to get the values of a subcollection base on a data range filter. However when I do the filtering I am getting all the values of the collection. For example for the following data I want to obtain only the values for dates in range 2019-01-01 to 2019-12-31 [ { symbol: "sensor1", data: [ { date: ISODate("2017-11-25T00:00:00.000Z"), value: 2.45, }, { date: ISODate("2019-11-26T00:00:00.000Z"), value: 2.2444 }, { date: ISODate("2019-12-25T00:00:00.000Z"), value: 2.5, }, { date: ISODate("2020-01-25T00:00:00.000Z"), value: 2.461, }, ] } ] Any recomendation? Thanks! Here is the playground: https://mongoplayground.net/p/UGpvgzjoFCi |
Fill form details to Instagram with Splash Posted: 15 Feb 2022 08:56 AM PST I'm trying to verify a login into instagram using a splash+lua script integration. Here's the script I am working with: - The first click is to accept the cookies
function main(splash) assert(splash:go(splash.args.url)) local get_dimensions = splash:jsfunc([[ function () { var rect = document.querySelector("button:nth-child(2)").getClientRects()[0]; return {"x": rect.left, "y": rect.top} } ]]) splash:set_viewport_full() splash:wait(2) local dimensions = get_dimensions() -- FIXME: button must be inside a viewport splash:mouse_click(dimensions.x, dimensions.y) -- Wait split second to allow event to propagate. splash:wait(4) local form = splash: select('#loginForm') local values = { username = 'foobar', password = 'foobar', } assert(form:fill(values)) assert(form:submit()) splash:wait(5) return splash:png() end However, when I run my lua script on docker I get the following screenshot: I cannot understand why this appears - as however it seems to occur when I implement the following into my script: local form = splash: select('#loginForm') local values = { username = 'foobar', password = 'foobar', } assert(form:fill(values)) assert(form:submit()) This is mainly a dummy login script so that I know I can correctly fill the form and click submit. I should be getting the following screenshout output: Additionally - I have also tried the following script that focuses on the CSS selectors and sends the text to fill the username and password. Finally, it clicks on the submit button afterwards. function main(splash) function focus(sel) splash:select(sel):focus() end assert(splash:go(splash.args.url)) local get_dimensions = splash:jsfunc([[ function () { var rect = document.querySelector("button:nth-child(2)").getClientRects()[0]; return {"x": rect.left, "y": rect.top} } ]]) splash:set_viewport_full() splash:wait(0.3) local dimensions = get_dimensions() -- FIXME: button must be inside a viewport splash:mouse_click(dimensions.x, dimensions.y) -- Wait split second to allow event to propagate. splash:wait(4) focus('input[name=username]') splash:send_text("foobar") assert(splash:wait(0.5)) focus('input[name=password]') splash:send_text("foobar") local get_submit = splash:jsfunc([[ function () { var rect = document.querySelector("button[type='submit']").getClientRects()[0]; return {"x": rect.left, "y": rect.top} } ]]) splash:wait(0.3) local submit = get_submit() -- FIXME: button must be inside a viewport splash:mouse_click(submit.x, submit.y) -- Wait split second to allow event to propagate. splash:wait(4) return splash:png() end However I get this error instead: attempt to index a nil value This issue seems to derive from the function focus . I have derived this from the docs here. |
R package access denied installation error Posted: 15 Feb 2022 08:55 AM PST Error in install.packages : path[1]="\Users\name\Documents\R\win-library\4.1": Access is denied I am trying to install basic r packages, and keep getting this error even though I have full permissions for this folder. I have tried different packages so it is something going on with my permissions. |
Can I use props in computed property to bind a css class? Posted: 15 Feb 2022 08:56 AM PST Is it possible to use the props inside a computed property, in some other way? When I do this, it add the class 'foo' (name of the props), instead the wanted 'fa-too' (or other value, if props were set). Both works, if I only bind one of them, directly in the markup. props: { foo: { type: String, default: 'fa-foo' } }, computed: { classObject: function () { return { foo: true, 'text-danger': true } } } |
How can I write a lambda expression that reads two different columns in a CSV file? Posted: 15 Feb 2022 08:56 AM PST for this particular problem, "countRespondentsByAgeRange" receives a stream of strings (CSV file) and returns a map with the count of respondents who watched any of the movies by age range (which are "18-29", "30-44", "45-60" or "> 60"). In this CSV file, the first two lines are column headers (so they don't matter basically) but the column that holds if they saw the movies or not ("Yes" or "No") is in column 2, but the column that holds the age range is column 31. I need to know how to filter out the stream to where if the respondent answered "Yes", it will take their age range and return the output for all of them. I only know how to copy one column into a List and look through there, but since you can't reuse a stream I don't know how to get the info for both. My attempt returns a map of all of the age ranges and how many are in there but I don't know how to filter it to show only the ones that are "Yes" My attempt: public static final Function<Stream<String>, Map<String, Long>> countRespondentsWhoHaveWatchedAnyOfTheSixMoviesByAgeRange = a -> { // list of the age ranges from participants List<String> strToList = a.map(s -> s.split(",")[30]).collect(Collectors.toList()); List<String> x = strToList.stream().filter(s -> s.startsWith("1")).collect(Collectors.toList()); List<String> y = strToList.stream().filter(s -> s.startsWith("3")).collect(Collectors.toList()); List<String> z = strToList.stream().filter(s -> s.startsWith("4")).collect(Collectors.toList()); List<String> old = strToList.stream().filter(s -> s.startsWith(">")).collect(Collectors.toList()); Long xVal = (long) x.size(); Long yVal = (long) y.size(); Long zVal = (long) z.size(); Long oVal = (long) old.size(); return Map.of("18-29", xVal, "30-44", yVal, "45-60", zVal, "> 60", oVal); }; Does anyone know how to do a shorter version of this lambda expression to just filter/sort through it to return this kind of map? |
Collecting coverage with playwright Posted: 15 Feb 2022 08:56 AM PST I'm struggling to set up coverage using Playwright. There are a lot of moving parts here and I might have misunderstood any number of steps. I'm attempting to follow this guide: https://playwright.dev/docs/api/class-coverage. Our project is a monorepo where tests in a folder e2e-tests/ run end to end tests on servers contained in other adjacent folders, e.g. frontend/ . The current setup is using page and afterEach fixtures like so in each test-file: // frontend.spec.ts import { test, expect } from "../fixtures"; test.afterEach(async ({ afterEach }) => { await afterEach(); }); test("something", ({ page ) => { // Do test stuff with page }); where the fixtures are defined as // fixtures/page.ts import { Page, chromium } from "@playwright/test"; const page = async () => { console.log("📈 Collecting coverage"); const browser = await chromium.launch(); const pageWithCoverage = await browser.newPage(); await pageWithCoverage.coverage.startJSCoverage(); return pageWithCoverage; }; and // fixtures/afterEach.ts import { Page } from "@playwright/test"; import v8toIstanbul from "v8-to-istanbul"; import * as fs from "fs"; import * as path from "path"; import * as crypto from "crypto"; const istanbulCLIOutput = path.join(process.cwd(), ".nyc_output"); const generateUUID = () => { return crypto.randomBytes(16).toString("hex"); }; const afterEach = ({ page }: { page: Page }) => async () => { const coverage = await page.coverage.stopJSCoverage(); fs.mkdirSync(istanbulCLIOutput, { recursive: true }); console.log("📈 Writing coverage"); for (const entry of coverage) { if (!entry.source) return; const converter = v8toIstanbul("", 0, { source: entry.source }); await converter.load(); converter.applyCoverage(entry.functions); const coverage = converter.toIstanbul(); // Entries with no path gives error with nyc if (Object.keys(coverage).some((path) => !path)) continue; const coverageString = JSON.stringify(coverage); const fileName = `playwright_coverage_${generateUUID()}.json`; fs.writeFileSync(path.join(istanbulCLIOutput, fileName), coverageString); } }; export default afterEach; Where I had to filter out entries with no path. Running npm t -- tests/frontend.spec.ts results in a bunch of files in .nyc_output , in fact I'm thinking there's probably something wrong with this setup since each test will generate thousands of files. But as far as I've understood the page object will be created anew for each test so this seems like the most obvious way? The problem is when I try to analyse the coverage from the tests; the result is empty (0 files in the report). I've tried the following: npx nyc report --all npx nyc report --all --include "../frontend/**" npx nyc report --all --include "../frontend/**/*.ts" When I analyse directly in the test run (npx nyc npm t -- tests/frontend.spec.ts ) it works, but only for files inside e2e-tests/ . If I again try to specify with --include "../frontend/**" it is empty. I have also tried using absolute path instead of relative to frontend/ . Can you see what the problem is? EDIT: I improved the setup a bit inspired by https://github.com/bgotink/playwright-coverage/blob/main/src/fixtures.ts, but the problem remains |
Using .searchable on a macOS causes the focus to always jump back to the search field Posted: 15 Feb 2022 08:55 AM PST I'm trying to move away from having a TextField in the toolbar by using the new .searchable . But there seems to be a problem I can't solve. When you type the text you want to search, I can filter the list with that text, but when I place the mouse cursor on the first item and try to move down the list with the arrow key, with each arrow key press, the focus goes back to the search field, making it impossible to navigate up and down the list with the keyboard. Maybe I'm not implementing it right, or maybe it doesn't work yet with macOS, either way, this is the code I'm using: struct AllNotes: View { @EnvironmentObject private var data: DataModel @State var selectedNoteId: UUID? @State var searchText: String = "" var body: some View { NavigationView { List(data.notes.filter { searchText.isEmpty ? true : $0.text.localizedCaseInsensitiveContains(searchText) }) { note in NavigationLink( destination: NoteView(note: note, text: note.text), tag: note.id, selection: $selectedNoteId ) { VStack(alignment: .leading) { Text(getFirstLine(noteText: note.text)).font(.body).fontWeight(.bold) } } } .searchable( text: $searchText, placement: .toolbar, prompt: "Search..." ) .listStyle(InsetListStyle()) .toolbar { // a few other buttons } } } } The DataModel is simple a struct of NoteItem: struct NoteItem: Codable, Hashable, Identifiable { let id: UUID var text: String var changed: Bool = false } Am I missing anything? Am I implementing this right? |
Swift adding items to array from text field input Posted: 15 Feb 2022 08:56 AM PST I am trying to display a list of items on a shopping list. These items are added from two text fields (description and quantity). For some reason, I am not able to get the array to keep the previous items, instead, the previous items in the array disappear and the only item that shows was the most recent item entered. Can someone help me understand where I have gone wrong? Here is the code I have: @IBAction func add(_ sender: UIButton) { var shoppingList = [String]() if let x = descriptionField.text{ if let y = quantityField.text{ if x != "" && y != "" { if isStringAnInt(string: y){ shoppingList.append("\(y) x \(x)") }else{ [...] |
How can I make Cloudinary image accessible from Strapi for my Gatsby site? Posted: 15 Feb 2022 08:56 AM PST I cannot access Cloudinary images from Strapi for my Gatsby site. I do the following... - Upload an image into Cloudinary.
- In the Strapi Media Library, click on the "Upload assets" button.
- I choose the "FROM URL" tab, paste the Cloudinary image link, and then upload it into Strapi.
- Go to my "Posts" Collection Type in Strapi, and add the new image from the Media Library and then save/publish the post.
- In Gatsby (graphql), I write the following...
query PostSearchQuery { allStrapiPost { edges { node { title subtitle slug id description image { localFile { childImageSharp { gatsbyImageData( layout: FULL_WIDTH placeholder: BLURRED aspectRatio: 1.3 ) } } } } } } } In http://localhost:8000/___graphql , I run it to check that the image data comes through and get this... "image": [ { "localFile": { "childImageSharp": { "gatsbyImageData": { "layout": "fullWidth", "placeholder": { "fallback": "data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAPABQDASIAAhEBAxEB/8QAGAAAAwEBAAAAAAAAAAAAAAAAAAQFAgP/xAAVAQEBAAAAAAAAAAAAAAAAAAADAv/aAAwDAQACEAMQAAAB7bkUCRkZAr//xAAbEAADAAIDAAAAAAAAAAAAAAABAgMAEgQRIf/aAAgBAQABBQKabZoezP1eRSYSyNMA5//EABURAQEAAAAAAAAAAAAAAAAAAAAS/9oACAEDAQE/AaU//8QAGBEAAwEBAAAAAAAAAAAAAAAAAAERITH/2gAIAQIBAT8Bk6N6f//EABwQAAEEAwEAAAAAAAAAAAAAAAABAhExEBJBYf/aAAgBAQAGPwLw5iJk2VXNWiz/xAAcEAEAAgIDAQAAAAAAAAAAAAABABEhMUFRcYH/2gAIAQEAAT8hoiOWnua93+y1UzHUeQEnPJcx5bH/2gAMAwEAAgADAAAAEIDf/8QAFxEBAQEBAAAAAAAAAAAAAAAAAREAIf/aAAgBAwEBPxBppzEm/8QAFxEAAwEAAAAAAAAAAAAAAAAAAAERQf/aAAgBAgEBPxC10OqM/8QAHBABAAMAAgMAAAAAAAAAAAAAAQARMSFRQXHw/9oACAEBAAE/ECpYHo6PqC4x2HWiXGFlVBol7SZKQJr9QxioVvjjwT//2Q==" }, "images": { "fallback": { "src": "/static/86c19d070d79399eb57c60d31989e521/a3208/you_bible_rvveya_a96c049ce9.jpg", "srcSet": "/static/86c19d070d79399eb57c60d31989e521/926c9/you_bible_rvveya_a96c049ce9.jpg 750w,\n/static/86c19d070d79399eb57c60d31989e521/4b650/you_bible_rvveya_a96c049ce9.jpg 1080w,\n/static/86c19d070d79399eb57c60d31989e521/4c7b3/you_bible_rvveya_a96c049ce9.jpg 1366w,\n/static/86c19d070d79399eb57c60d31989e521/a3208/you_bible_rvveya_a96c049ce9.jpg 1920w", "sizes": "100vw" }, "sources": [ { "srcSet": "/static/86c19d070d79399eb57c60d31989e521/b1001/you_bible_rvveya_a96c049ce9.webp 750w,\n/static/86c19d070d79399eb57c60d31989e521/a6f88/you_bible_rvveya_a96c049ce9.webp 1080w,\n/static/86c19d070d79399eb57c60d31989e521/36c2a/you_bible_rvveya_a96c049ce9.webp 1366w,\n/static/86c19d070d79399eb57c60d31989e521/1d7d9/you_bible_rvveya_a96c049ce9.webp 1920w", "type": "image/webp", "sizes": "100vw" } ] }, "width": 1, "height": 0.7692708333333333 } } } } ] All so far, so good. The image shows up in graphql. But then when I attempt to display the image using this... import React from "react" import { Link } from "gatsby" import PropTypes from "prop-types" import Card from "~/components/styled/card" import Image from "~/components/image" const PostList = ({ posts, gridCols }) => { return ( <div className={`grid ${gridCols} gap-6`}> {posts.map(post => { return ( <Card key={post.id}> <Link to={`/posts/${post.slug}`} key={post.id}> <Image alt="Post Image" className="rounded-t-md border-gray-200 border-b" image={post.image} /> <div className="px-4 py-6"> <p>{post.title}</p> <p className="text-xs self-end"> {post.subtitle} </p> </div> </Link> </Card> ) })} </div> ) } PostList.propTypes = { posts: PropTypes.array, gridCols: PropTypes.string, } PostList.defaultProps = { gridCols: "grid-cols-1 md:grid-cols-3", } export default PostList ..with this being the Image component... import React from "react" import { useStaticQuery, graphql } from "gatsby" import { GatsbyImage, getImage } from "gatsby-plugin-image" import PropTypes from "prop-types" const Image = ({ image, className, alt }) => { const data = useStaticQuery(graphql` query { strapiGlobal { placeHolder { localFile { childImageSharp { gatsbyImageData( layout: FULL_WIDTH placeholder: BLURRED aspectRatio: 1.3 ) } } } } } `) if (!image) { return ( <GatsbyImage className={className} image={getImage(data.strapiGlobal.placeHolder.localFile)} alt="Placeholder Image" /> ) } return ( <GatsbyImage alt={alt} className={className} image={getImage(image.localFile)} /> ) } Image.propTypes = { image: PropTypes.object.isRequired, className: PropTypes.string, alt: PropTypes.string.isRequired, } export default Image ...it comes up blank. Not sure what I'm missing here. I've run gatsby clean before gatsby develop , but the image still doesn't show. What's strange about this is that in my "Products" Collection Type in Strapi, the images do show up. (That was in the original Gatsby starter I'm using as a template for this site.). In other words, when I add a new Collection Type, my images don't show up in the Gatsby site. Any help with this would be much appreciated. |
CommonsRequestLoggingFilter not logging when extending Posted: 15 Feb 2022 08:56 AM PST The following code does not log when I add in the override methods. If I comment them out, it does log when I issue a logger.error() in the ControllerAdvice. Using the following property in application.properties. logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=TRACE Using Spring Boot 2.4.5 @Bean public CommonsRequestLoggingFilter logFilter() { CommonsRequestLoggingFilter filter = new CommonsRequestLoggingFilter() { @Override protected void beforeRequest(HttpServletRequest request, String message) { logger.info(message); } @Override protected void afterRequest(HttpServletRequest request, String message) { logger.info(message); } }; filter.setIncludeClientInfo(true); filter.setIncludeHeaders(true); filter.setIncludePayload(true); filter.setIncludeQueryString(true); filter.setBeforeMessagePrefix("Request started => "); filter.setAfterMessagePrefix("Request ended => "); return filter; } |
Grouping consecutive rows by date in PySpark Dataframe Posted: 15 Feb 2022 08:55 AM PST I have managed to get the dataframe with these columns: +----------+----------+--------+ | date| next_date|datediff| +----------+----------+--------+ |2020-09-25|2020-09-30| 5| |2020-09-30|2020-10-01| 1| |2020-10-01|2020-10-02| 1| |2020-10-02|2020-10-03| 1| |2020-10-03|2020-10-04| 1| |2020-10-09|2020-11-23| 45| |2020-11-23|2020-11-24| 1| |2020-11-24|2020-11-25| 1| |2020-11-25|2020-11-26| 1| +----------+----------+--------+ I got the 'group' column by doing these commands: w1 = Window.orderBy("date") df_dates.withColumn( "dateChange", (F.col("datediff") != F.lit(1)).cast("int") )\ .fillna( 0, subset=["dateChange"] )\ .withColumn( "indicator", (~((F.col("dateChange")==0))).cast("int") )\ .withColumn( "group", F.sum(F.col("indicator")).over(w1.rangeBetween(Window.unboundedPreceding, 0)) ) and finally got these groupings: +----------+----------+--------+----------+---------+-----+ | date| next_date|datediff|dateChange|indicator|group| +----------+----------+--------+----------+---------+-----+ |2020-09-25|2020-09-30| 5| 1| 1| 1| |2020-09-30|2020-10-01| 1| 0| 0| 1| |2020-10-01|2020-10-02| 1| 0| 0| 1| |2020-10-02|2020-10-03| 1| 0| 0| 1| |2020-10-03|2020-10-04| 1| 0| 0| 1| |2020-10-09|2020-11-23| 45| 1| 1| 2| |2020-11-23|2020-11-24| 1| 0| 0| 2| |2020-11-24|2020-11-25| 1| 0| 0| 2| |2020-11-25|2020-11-26| 1| 0| 0| 2| +----------+----------+--------+----------+---------+-----+ However, the first row should have its own group. The second row should be group 2 (all incremented by 1). Then I do the aggregation: df_dates.groupBy("group")\ .agg( F.min("next_date").alias("start_time"), F.max("next_date").alias("end_time") )\ .drop("group")\ .show() +----------+----------+ |start_time| end_time| +----------+----------+ |2020-09-30|2020-10-04| |2020-11-23|2020-11-26| +----------+----------+ But I am missing the first group which is 2020-09-25. The aim for this is to get the ranges for consecutive dates to help me combine HDFS folders with consecutive dates into the same partition. |
CLR dll cant run Managed DLL unless it locate inside the exe directory (or its subdirectory) Posted: 15 Feb 2022 08:55 AM PST I have this situation: - Two C++ applications that load plugin DLLs at runtime.
- A Plugin DLL with CLR\CLI support, with a reference to a managed (C#) DLL.
- The managed (C#) DLL.
It is ordered like this: - The first app stored in app1 dir
- The second app stored in app2 dir
- All the plugin DLLs, with dependencies (CLR and managed) are in plugin dir, which is parallel to app1 and app2
The problem is that if the managed DLL can't be loaded from the plugin DLL unless it is in the executable dir (app1, app2). I really prefer it will be located in the plugin dir since logically it should be used from the plugin and not from the apps, and I want to avoid duplications, the plugin directory can't be located as a subdirectory of the app since I have two apps. .NET applications can be configured with a .config file to enable Assembly Binding from other directories, but again, this is a C++ application. In addition, I've read about the config files, and it wrote it can be used only for subdirectories. I quote: (from this link) privatePath Required attribute. Specifies subdirectories of the application's base directory that might contain assemblies. Delimit each subdirectory with a semicolon. Just to clarify: I don't have a problem running other DLLs from the plugin (the plugin directory is in the %PATH% environment), I have a problem only loading the managed DLLs. So, my question is: how can I enable the managed DLL to run from a custom dir, which is not a sub-directory of the executable? I'm looking for a working solution, without duplications of files or directories. Example: C# (managed) DLL using System; namespace PrintSample { public class CPrintSample { void print() { Console.WriteLine("Hello"); } } } CLR DLL (with reference to C# PrintSample added and CLR_PRINT_SAMPLE_EXPORT defined in preprocessor) clr_sample.h #pragma once #ifdef CLR_PRINT_SAMPLE_EXPORT #define CLR_PS_API __declspec(dllexport) #else #define CLR_PS_API __declspec(dllimport)
|
No comments:
Post a Comment