Posts

Showing posts from August 27, 2018

How to check custom attributes inside authorization process (policy or middleware)?

Image
Clash Royale CLAN TAG #URR8PPP How to check custom attributes inside authorization process (policy or middleware)? Main goal is to prevent access to the portal when OIDC user has custom claim with type 'BlockedFrom', which added in ClaimsTransformation. I've solved it by middleware in Startup.Configure method. General reason is to keep original request URL without redirection to /Account/AccessDenied page. Startup.Configure app.Use((context, next) => var user = context.User; if (user.IsAuthenticated()) // Do not rewrite path when it marked with custom [AllowBlockedAttribute]! // /Home/Logout, for example. But how? // if (user.HasClaim(x => x.Type == UserClaimTypes.BlockedFrom)) // Rewrite to run specific method of HomeController for blocked users // with detailed message. // context.Request.Path = GenericPaths.Blocked; return next(); ); But have one unexpected result: the Logout method of HomeController is blocked too. User can't logout when

del tuple-keys from nested dict; avoid runtime and type error

Image
Clash Royale CLAN TAG #URR8PPP del tuple-keys from nested dict; avoid runtime and type error I have generated a large, nested dictionary from a pandas dataframe that was originally from an .xlsx sheet. Through the process, some of the empty cells from my excel sheet were imported as 'nan' and the values are stored in tuples, which serve as keys. The resulting dictionary looks something like this: d_nans = 'feature1': ('1', '2'): ['item1':'value1', 'item2': 'value2'], ('nan', 'nan'): ['item3':'value3', 'item4': 'value4'], 'feature2': ('3', '10'): ['item5':'value5', 'item6': 'value6'], ('nan', 'nan'): ['item7':'value7', 'item8': 'value8'], ('23', '40'): ['item9':'value9', 'item10': 'value10'], 'feature3': ('21

Issue with sticky header and pure css parallax

Image
Clash Royale CLAN TAG #URR8PPP Issue with sticky header and pure css parallax $(window.parent).scroll(function() if ($(window.parent).scrollTop() >= 410) $('nav').addClass('sticky'); else $('nav').removeClass('sticky'); ); /*! HTML5 Boilerplate v6.1.0 | MIT License | https://html5boilerplate.com/ */ /* * What follows is the result of much research on cross-browser styling. * Credit left inline and big thanks to Nicolas Gallagher, Jonathan Neal, * Kroc Camen, and the H5BP dev community and team. */ /* ========================================================================== Base styles: opinionated defaults ========================================================================== */ html color: #222; line-height: 1.4; font-family: Helvetica, Arial, sans-serif; font-size: 1vw; width: 100%; overflow-x: hidden; body overflow-x: hidden; /*HKEY_CURRENT_USERSoftwareMicrosoft WindowsCurrentVersionPoliciesExplorer * Remove text-shadow

Loop ExpandableListview children for each parent

Image
Clash Royale CLAN TAG #URR8PPP Loop ExpandableListview children for each parent I am trying to assign each of the children in my expandable listview to its proper parents, but I ended up assigning all child data to each parent in the list view. This is my activity: api.USER_VM_LIST(UserId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Observer<UserVmList>() @Override public void onCompleted() @Override public void onError(Throwable e) @Override public void onNext(UserVmList userVmList) listVmTitle = new ArrayList<>(); listHashMap = new HashMap<>(); List<DetailsOfVmObject> detailsOfVmObjects = new ArrayList<>(); for (int i = 0; i < userVmList.getVm_data().size(); i++) //loop Listview RowTitle VmObject vmObject = new VmObject(userVmList.getVm_data().get(i).getHostname(), userVmList.getVm_data().get(i).getStatus(), userVmList.getVm_data().get(i).getImage()); listVmTitle.add(vmObject); //Loop

Fab in Coordinator layout with bottom padding

Image
Clash Royale CLAN TAG #URR8PPP Fab in Coordinator layout with bottom padding Fab is in coordinator layout, coordinator layout has bottom padding. There is incorrect fab behavior when snackbar showing: Snackbar appeared: Snackbar disappeared This is my layout: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="56dp" > <android.support.design.widget.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" > <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_

Return variable after setTimeout

Image
Clash Royale CLAN TAG #URR8PPP Return variable after setTimeout I'm trying to return a variable only after it has been set within a setTimeout callback. I couldn't think of any other way to do this, but here's my attempt (I know the code seems silly, but it's to work around a Cordova bug). For reasons beyond my understanding, it results in an infinite loop. function isConnected() var done = false; setTimeout(function() done = true; , 500); while (!done) return navigator.connection.type!== Connection.NONE; Can anyone explain to me why this is happening, or provide an alternative? Update (solution): function isConnected(callback) setTimeout(function() callback(navigator.connection.type !== Connection.NONE); , 500); isConnected(function(connected) if (!connected) alert('Not Connected'); ); 3 Answers 3 You simply can't solve your problem that way. Because javascript is single threaded, the setTimeout callback can only run when your JS thread

How to check connectivity of a directed graph in Python?

Image
Clash Royale CLAN TAG #URR8PPP How to check connectivity of a directed graph in Python? Is there any way in Python's networkx to check for connectivity of a directed graph? If not in networkx, how else may this be achieved in Python? There is the subpackage networkx.connectivity — have you checked there? – L3viathan Aug 13 at 8:29 networkx.connectivity I believe that only operates on undirected graphs. I think the is_strongly_connected function will provide me with what I am seeking. I would really like to know how this works though? i.e. what algorithms does it use to calculate the result? – BRavos Aug 15 at 7:50 Nevermind, found it here: networkx.github.io/documentation/latest/_modules/networkx/… – BRavos Aug 15 at 8:14 By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

How to find the element from the HTML provided through Selenium and Python?

Image
Clash Royale CLAN TAG #URR8PPP How to find the element from the HTML provided through Selenium and Python? Actually this button is located inside container. Please provide syntax for python Here this property has unique name, but dont know how to use this [data-control-name="job_search_category_suggestion_it"] [data-control-name="job_search_category_suggestion_it"] <button class="jobs-search-category-suggestions__button button-secondary-medium-muted mb2 mr2" data-control-name="job_search_category_suggestion_it" data-ember-action="" data-ember-action-8126="8126"> <li-icon aria-hidden="true" type="search-icon" size="small"><svg viewBox="0 0 24 24" width="24px" height="24px" x="0" y="0" preserveAspectRatio="xMinYMin meet" class="artdeco-icon" focusable="false"><path d="M14,12.67L11.13,9.8A5,5,

Can I combine the creation of an element and adding a new element together in Xamarin.Forms?

Image
Clash Royale CLAN TAG #URR8PPP Can I combine the creation of an element and adding a new element together in Xamarin.Forms? I have this code: var layout = new StackLayout Orientation = StackOrientation.Vertical,     Spacing = 0 ; layout.Children.Add(new HeaderTemplate     Header = Settings.cc.LongText().ToUpper() ); Can these two statements be combined in some way? Not possible, you will need an instance before being able to add children. There is no support in C# at this time to do that from the initialization. – Gerald Versluis Aug 13 at 8:22 @GeraldVersluis ? Children is an IList<View> , so yes you can add a comma separated list of children in StackLayout constructor via the initializer shorthand. Now I have no idea what a HeaderTemplate custom(?) class is (ListView has one), so assuming it is a View subclass, that would work fine. ) – SushiHangover Aug 13 at 9:52 Children IList<View> HeaderTemplate @SushiHangover my mistake, you are right. As poi

How to ensure MySQL connection of Spring @Transactional annotation use is the same with the one in method?

Image
Clash Royale CLAN TAG #URR8PPP How to ensure MySQL connection of Spring @Transactional annotation use is the same with the one in method? If use @Transactional to annotate a method, the method will be transactional. If use DataSourceTransactionManager as transactionManager, JDBC connections will be managed. DataSourceTransactionManager Example: @Transactional public void insertOrder() //insert log info //insertOrder //updateAccount It seems that @Transactional help a DB connection start a transaction, insertOrder and updateAccount will use the same connection to modify data. @Transactional insertOrder updateAccount How does it do this? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Set the value of uncheck jquery checkbox

Image
Clash Royale CLAN TAG #URR8PPP Set the value of uncheck jquery checkbox Hi I am new to javascript, html and jquery. I would really appreciate any help or suggestion thanks in advance. I am trying to set the value of jquery checkbox to No if uncheck I adden an html code hidden with the same name of my jquery checkbox before my jquery checkbox <input type="hidden" name="c1" value="No" /> actually it saving No if uncheck however if it is checked it saving as Yes;No my jquesry check box <input grouping="" id="c1" name="c1" type="checkbox" value="Yes" /> do you have 2 inputs with the same name attribute? that wont work – Alex Aug 13 at 7:57 name I only have one checkbox but did create <input type="hidden" name="c1" value="No" /> and it saving no if the checkbox is uncheck however storing and displaying Yes;No if check box is checked – Aika Aug 13 a

Next and Previous Page Buttons for iFrame content

Image
Clash Royale CLAN TAG #URR8PPP Next and Previous Page Buttons for iFrame content I made a website where there are a bunch of links that load into an iframe. There are buttons that allow the user to navigate to the next and previous links in the list. I used this to do that. var i = 0, links = $('a').toArray(); $('.next').click(function() i++; if(i === links.length) i = links.length - 1; $('.frame').attr('src', links[i]); ); //loads next link in iframe $('.prev').click(function() i--; if(i < 0) i = 0; $('.frame').attr('src', links[i]); ); //loads previous link in iframe The problem is that if a user clicks on say the 3rd link, and then clicks the next button, it does not go to the 4th link, but rather to the 2nd link, since the click function just changes the value of i which is set to 0 by default. To solve this I thought of creating another variable that stored the current link loaded in the iframe as such: var curr

After update knockout.js and SignalR libraries knockout-mapping js not update the list in view

Image
Clash Royale CLAN TAG #URR8PPP After update knockout.js and SignalR libraries knockout-mapping js not update the list in view I have following code. but not update the view page. In my app.js // Hub Callback: Update User List hub.client.updateUserList = function (userList) viewModel.setUsers(userList); ; In my viewmodel.js var viewModel = Users: ko.mapping.fromJS(), viewModel.setUsers = function (userArray) ko.mapping.fromJS(userArray, viewModel.Users); ; My SignalR hub class private void SendUserListUpdate() Users.ForEach(u => u.InCall = (GetUserCall(u.ConnectionId) != null)); Clients.All.updateUserList(Users); This signalR SendUserListUpdate() correctly update the users list. But not update in below index page. <div class="well user-list"> <ul class="nav nav-list"> <li class="nav-header">Online Users <small data-bind="text: Users().length"></small></li> <!-- ko foreach: Users -

How to use Enum's in a foreach loop where the Enum represents a property field and acts as counter (Months)?

Image
Clash Royale CLAN TAG #URR8PPP How to use Enum's in a foreach loop where the Enum represents a property field and acts as counter (Months)? I need to generate some hour accounts if they don't exist and tried to make the method as easy as possible. Unfortunately I'm stuck at the following. This is how I would check / create an account for every month: // January if (!_db.Stundenkonto.Any(x => x.MitarbeiterId == mitarbeiterId && x.Jahr == jahr && x.Monat == 1)) HrsAccount acc = new HrsAccount AccountId = new Guid(), UserId = loggedInUser, Month = 1 <<--- This is where I'd need the number of the Enum - 1, HoursToWork = model.data[0].january <<--- Here I'd need the name of the Enum HoursWorked = model.data[1].january <<-- Same here So as you can see I need number AND value of the Enum. I tried: foreach (MonthEnum month in Enum.GetValues(typeof(MonthEnum))) HrsAccount acc = new HrsAccount AccountId = new Guid(), UserId