Kotlin reduce function for 2d list not working

Uncategorized
Question: I need to get a total size of a 2d list. This is my implementation: fun totalSize(parts: List): Int { return parts.reduce { total, next -> total + next.size } } I get type inference fail. Required Int, Got List. But next.size should return Int. Answer: Just map the inner lists to their sizes first. My guess in Kotlin syntax:parts.map { l -> l.size }.reduce { total, i -> total + i } Read more
Read More

How to make the right conditions using firebase authentication in react native?

javascript
Question: I created a simple form to using firebase authentication with react native. But when I try, my state always show success even failed to auth. Success label always appear before then followed by a failed label. Although in fact the same enter the wrong password with the correct email. Here is my code ://import libraries import React, { Component } from 'react'; import { View, Text, ToastAndroid } from 'react-native'; import { Button, Card, CardSection, Input, Spinner } from './common'; import firebase from 'firebase'; // create a component class LoginForm extends Component { state = { email: '', password:'', error: '', success: '', loading: false }; onButtonPress() { const {email, password} = this.state; if(this.state.email == '') { this.setState({ error: 'Email can not be empty', loading: false }); } else…
Read More

How to open and close python socket

Uncategorized
Question: I have a c++ program that reads sensor data from GPIO from a rpi. I want to pass this data to my computer over Ethernet (cannot do Wi-Fi). I am calling a python script from cpp to post 1 data byte to the socket. I want to close the socket and end the py script, then do my next read in cpp, then call the same python script again to reopen the same socket and post the next data. How do I make this script modular? Additionally (optional) (1) how do I do ubuntu sockets in cpp? (2) how do I pass a cpp variable to the transmit python script as the data in a cpp program? The below script for transmit and receive work great in continuous mode,…
Read More

Medix Medical HTML5 Template

Uncategorized
Medix is a clean-coded and responsive HTML5 template for health care services, medical practitioners and clinics to set up a convenient website. The template comes with different versatile and neat page layouts which can help to present highlight features like medical staff, services and pricings list. Other features like social links support, on-scroll animations and great hover effect will bring pleasant browsing experience for your visitors. The template is also ensured to be responsive on different devices like mobile, tablet, desktops, which enables patients to access anywhere any time.
Read More

PHP if no post statement

Uncategorized
Question: I am trying to make an IF statement for below code. The below code allows me to create the relationship between post types through ACF custom relationship. Publication post type is general post types like Sport and Publication_res is specific publications like football, basketball etc. Then, I create this field for multiple pages (football, basketball, badminton etc.) but however, not all these pages have publication but however this below sidebar still appears for those pages that have no publication linked. So my request is when there is a publication linked, the sidebar should appear. Otherwise, it should not appear. Thank you for your help in advance. " class="underline"> Answer: Read more
Read More

How to enable C++17 in CMake

Uncategorized
Question: I'm using VS 15.3, which supports integrated CMake 3.8. How can I target C++17 without writing flags for each specific compilers? My current global settings don't work:# https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # expected behaviour #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++lastest") I expected CMake to add "/std:c++lastest" or equivalents when generating VS solution files, but no c++17 flags was found, resulted in compiler error:C1189 #error: class template optional is only available with C++17. Answer: You can keep that set(CMAKE_CXX_STANDARD 17) for other compilers, like Clang and GCC. But for Visual Studio, it's useless. If CMake still doesn't support this, you can do the following:if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17") endif(MSVC) Read more
Read More

RecyclerView scroll to top after back navigation if adapter's data set through RxAndroid

Uncategorized
Question: When I set adapter's data directly then the scroll position of the list is correct after I come back from detial fragment, but If I'm using RXAndroid to handle data then the scroll is always jump to the top. Here is an example about my problem:public class ListFragment extends Fragment { private MyAdapter adapter; private List data = new ArrayList(); @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); for (int i = 1; i < 30; i++) { data.add("POS: " + i); } } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_list, container, false); adapter = new MyAdapter(); ((RecyclerView) root.findViewById(R.id.bone_list)).setAdapter(adapter); return root; } @Override public void onResume() { super.onResume(); data.add("POS: " + (data.size() + 1)); // Working //adapter.setData(data); // Not…
Read More

Gradi – Fresh Tumblr Theme for Modern Businesses and Startups

Uncategorized
Gradi – Fresh Tumblr Theme for Modern Businesses and Startups is a clean and beautifully designed Tumblr Theme that is an ideal fit for business and startup purpose. Gradi is easy to use, awesome and powerful. These are the words that we talk about Gradi. You will be able to build your website in a snap without coding knowledge. Are you ready to get it for now?
Read More

Missing proper which command. Make sure it is installed before using RVM

Uncategorized
Question: I think I install Magnet in Mac and remove better touch tool, then my terminal suddenly gets this:Last login: Tue Aug 15 16:23:47 on ttys000 ERROR: Missing proper 'which' command. Make sure it is installed before using RVM! WARNING:Errors sourcing '/Users/kenpeter/.rvm/scripts/base'. RVM will likely not work as expected. ERROR: Missing proper 'which' command. Make sure it is installed before using RVM! WARNING:Errors sourcing '/Users/kenpeter/.rvm/scripts/base'. RVM will likely not work as expected. When I type which in terminal, it works. My question is that, how do I get rid of this warning? Answer: I did yarn global install xxxx. It causes rvm to complain. yarn global remove xxxx Fix the issue. Ref: https://issues.jenkins-ci.org/browse/JENKINS-20636?page=com.atlassian.jira.plugin.system.issuetabpanels%3Achangehistory-tabpanel https://github.com/yarnpkg/yarn/issues/2064 Read more
Read More