samson | Web interface for deployments , with plugin architecture | Continuous Deployment library

 by   zendesk Ruby Version: v3370 License: Non-SPDX

kandi X-RAY | samson Summary

samson is a Ruby library typically used in Devops, Continuous Deployment, Docker applications. samson has no bugs, it has no vulnerabilities and it has medium support. However samson has a Non-SPDX License. You can download it from GitHub.
Samson is a web interface for deployments. Live Demo It is currently in maintenance mode (bugfix, but no new features) because we are migrating off it.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        samson has a medium active ecosystem.
                        summary
                        It has 1440 star(s) with 238 fork(s). There are 421 watchers for this library.
                        summary
                        There were 8 major release(s) in the last 6 months.
                        summary
                        There are 74 open issues and 215 have been closed. On average issues are closed in 97 days. There are 11 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of samson is v3370
                        samson Support
                          Best in #Continuous Deployment
                            Average in #Continuous Deployment
                            samson Support
                              Best in #Continuous Deployment
                                Average in #Continuous Deployment

                                  kandi-Quality Quality

                                    summary
                                    samson has 0 bugs and 0 code smells.
                                    samson Quality
                                      Best in #Continuous Deployment
                                        Average in #Continuous Deployment
                                        samson Quality
                                          Best in #Continuous Deployment
                                            Average in #Continuous Deployment

                                              kandi-Security Security

                                                summary
                                                samson has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                samson code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                samson Security
                                                  Best in #Continuous Deployment
                                                    Average in #Continuous Deployment
                                                    samson Security
                                                      Best in #Continuous Deployment
                                                        Average in #Continuous Deployment

                                                          kandi-License License

                                                            summary
                                                            samson has a Non-SPDX License.
                                                            summary
                                                            Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
                                                            samson License
                                                              Best in #Continuous Deployment
                                                                Average in #Continuous Deployment
                                                                samson License
                                                                  Best in #Continuous Deployment
                                                                    Average in #Continuous Deployment

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        samson releases are available to install and integrate.
                                                                        samson Reuse
                                                                          Best in #Continuous Deployment
                                                                            Average in #Continuous Deployment
                                                                            samson Reuse
                                                                              Best in #Continuous Deployment
                                                                                Average in #Continuous Deployment
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi has reviewed samson and discovered the below as its top functions. This is intended to give you an instant insight into samson implemented functionality, and help decide if they suit your requirements.
                                                                                  • Set the secret from the secret
                                                                                    • Creates an object for a given attribute .
                                                                                      • Gets the slack user s slack .
                                                                                        • Prints the stage for a stage .
                                                                                          • Determines the role of the deployment
                                                                                            • Get the job for a given query
                                                                                              • Saves environment variables
                                                                                                • Creates a new commit .
                                                                                                  • Shows the deployment
                                                                                                    • Find page by id
                                                                                                      Get all kandi verified functions for this library.
                                                                                                      Get all kandi verified functions for this library.

                                                                                                      samson Key Features

                                                                                                      Web interface for deployments, with plugin architecture and kubernetes support

                                                                                                      samson Examples and Code Snippets

                                                                                                      No Code Snippets are available at this moment for samson.
                                                                                                      Community Discussions

                                                                                                      Trending Discussions on samson

                                                                                                      Most efficient way to loop through a file's values and check a dictionary for any/all corresponding instances
                                                                                                      chevron right
                                                                                                      Randomly swap 2 elements of array with another 2 elements
                                                                                                      chevron right
                                                                                                      I am failing to correctly loop through an xml file with python, how can I loop through and return multiple different tags in the correct order?
                                                                                                      chevron right
                                                                                                      Nokogiri & returning all data between two tags
                                                                                                      chevron right
                                                                                                      how to display cities in one dropdown based on selected state in other dropdown using json data in angular ionic?
                                                                                                      chevron right
                                                                                                      RUBY: Rotate Function not Working on Array in Unit Test
                                                                                                      chevron right
                                                                                                      Javascript Filter trying to avoid multiple if statements
                                                                                                      chevron right
                                                                                                      Toggle Accordion functionality with reactstrap?
                                                                                                      chevron right
                                                                                                      group result using date from object keys and only get count the results
                                                                                                      chevron right
                                                                                                      Get name HttpClient from IHttpClientFactory injected with DI
                                                                                                      chevron right

                                                                                                      QUESTION

                                                                                                      Most efficient way to loop through a file's values and check a dictionary for any/all corresponding instances
                                                                                                      Asked 2022-Apr-04 at 14:17

                                                                                                      I have a file with user's names, one per line, and I need to compare each name in the file to all values in a csv file and make note each time the user name appears in the csv file. I need to make the search as efficient as possible as the csv file is 40K lines long

                                                                                                      My example persons.txt file:

                                                                                                      Smith, Robert
                                                                                                      Samson, David
                                                                                                      Martin, Patricia
                                                                                                      Simpson, Marge
                                                                                                      

                                                                                                      My example locations.csv file:

                                                                                                      GreaterLocation,LesserLocation,GroupName,DisplayName,InBook
                                                                                                      NorthernHemisphere,UnitedStates,Pilots,"Wilbur, Andy, super pilot",Yes
                                                                                                      WesternHemisphere,China,Pilots,"Kirby, Mabry, loves pizza",Yes
                                                                                                      WesternHemisphere,Japan,Drivers,"Samson, David, big kahuna",Yes
                                                                                                      NortherHemisphere,Canada,Drivers,"Randos, Jorge",Yes
                                                                                                      SouthernHemispher,Australia,Mechanics,"Freeman, Gordon",Yes
                                                                                                      NortherHemisphere,Mexico,Pilots,"Simpson, Marge",Yes
                                                                                                      SouthernHemispher,New Zealand,Mechanics,"Samson, David",Yes
                                                                                                      

                                                                                                      My Code:

                                                                                                      import csv
                                                                                                      
                                                                                                      def parse_files():
                                                                                                      
                                                                                                          with open('data_file/persons.txt', 'r') as user_list:
                                                                                                              lines = user_list.readlines()
                                                                                                              for user_row in lines:
                                                                                                                  new_user = user_row.strip()
                                                                                                                  per = []
                                                                                                                  with open('data_file/locations.csv', newline='') as target_csv:
                                                                                                                      DictReader_loc = csv.DictReader(target_csv)
                                                                                                                  
                                                                                                                      for loc_row in DictReader_loc:
                                                                                                                          if new_user.lower() in loc_row['DisplayName'].lower():
                                                                                                                              per.append(DictReader_loc.line_num)
                                                                                                                              print(DictReader_loc.line_num, loc_row['DisplayName'])
                                                                                                                  if len(per) > 0:
                                                                                                                      print("\n"+new_user, per)
                                                                                                          print("Parse Complete")
                                                                                                              
                                                                                                      def main():
                                                                                                          parse_files()
                                                                                                      
                                                                                                      main()
                                                                                                      

                                                                                                      My code currently works. Based on the sample data in the example files, the code matches the 2 instances of "Samson, David" and 1 instance of "Simpson, Marge" in the locations.csv file. I'm hoping that someone can give me guidance on how I might transform either the persons.txt file or the locations.csv file (40K+ lines) so that the process is as efficient as it can be. I think it currently takes 10-15 minutes. I know looping isn't the most efficient, but I do need to check each name and see where it appears in the csv file.

                                                                                                      ANSWER

                                                                                                      Answered 2022-Mar-15 at 16:08

                                                                                                      I think @Tomalak's solution with SQLite is very useful, but if you want to keep it closer to your original code, see the version below.

                                                                                                      Effectively, it reduces the amount of file opening/closing/reading that is going on, and hopefully will speed things up.

                                                                                                      Since your sample is very small, I could not do any real measurements.

                                                                                                      Going forward, you can consider using pandas for these kind of tasks - it can be very convenient working with CSVs and more optimized than the csv module.

                                                                                                      import csv
                                                                                                      
                                                                                                      def parse_files():
                                                                                                          with open('persons.txt', 'r') as user_list:
                                                                                                              # sets are faster to match against than lists
                                                                                                              # do the lower() here to avoid repetition
                                                                                                              user_set  = set([u.strip().lower() for u in user_list.readlines()])
                                                                                                          # open file at beginning, close after done
                                                                                                          # you could also encapsulate the whole thing into a `with` clause if
                                                                                                          # desired
                                                                                                          target_csv = open("locations.csv", "r", newline='')
                                                                                                          DictReader_loc = csv.DictReader(target_csv)
                                                                                                          for user in user_set:
                                                                                                              per = []
                                                                                                              for loc_row in DictReader_loc:
                                                                                                                  if user in loc_row['DisplayName'].lower():
                                                                                                                      per.append(DictReader_loc.line_num)
                                                                                                                      print(DictReader_loc.line_num, loc_row['DisplayName'])
                                                                                                              if len(per) > 0:
                                                                                                                  print("\n"+user, per)
                                                                                                          print("Parse Complete")
                                                                                                          target_csv.close()
                                                                                                              
                                                                                                      def main():
                                                                                                          parse_files()
                                                                                                      
                                                                                                      main()
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/71462285

                                                                                                      QUESTION

                                                                                                      Randomly swap 2 elements of array with another 2 elements
                                                                                                      Asked 2021-Oct-05 at 20:09

                                                                                                      I have a list of team members and a list of 2 substitutes: team = Samson, Max, Rowan, Flynn, Jack subs = Struan, Harry

                                                                                                      I need to randomly swap the 2 subs into the team. I'm getting stuck because I need to ensure that only these 2 elements are swapped and that both are swapped in. I tried just looping through the subs array and randomly swapping each element with an element from the team array, but too frequently it swapped Struan with Max and then Harry with Struan, so that in the end Struan was still in the subs array and not in the team.

                                                                                                      So: I need to exclusively swap the 2 elements in the sub array with random elements from the team array. How can I do that?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Oct-05 at 19:08

                                                                                                      This should work:

                                                                                                      function getRandomItem () {
                                                                                                         let randomItem = team[Math.floor(Math.random()*team.length)];
                                                                                                         if(subs.indexOf(randomItem)<0){
                                                                                                            return randomItem;
                                                                                                         } else {
                                                                                                            return getRandomItem();
                                                                                                         }
                                                                                                      }
                                                                                                      
                                                                                                      subs.forEach((item,i)=>{
                                                                                                         subs.splice(i,1,getRandomItem());
                                                                                                      }
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/69455911

                                                                                                      QUESTION

                                                                                                      I am failing to correctly loop through an xml file with python, how can I loop through and return multiple different tags in the correct order?
                                                                                                      Asked 2021-Sep-16 at 15:34

                                                                                                      I have an XML file from which I need to return the text from various tags, CompanyName, FirstName, LastName, Content, Time etc.

                                                                                                      So far I can return the text of every iterance of one of the tags using a for each loop, or I can return all of the required data but in consecutive blocks.

                                                                                                      What I am struggling to find the answer to is, how to return the appropriate text from the specified tags in the correct chronological order as they appear in the XML document.

                                                                                                      Below I will describe what I have already tried.

                                                                                                      Firstly, here is the XML content I am parsing:

                                                                                                      
                                                                                                      
                                                                                                      1.3
                                                                                                      
                                                                                                      1
                                                                                                      09/09/2021 19:35:35
                                                                                                      1631216135
                                                                                                      
                                                                                                      
                                                                                                      JJohnson
                                                                                                      John
                                                                                                      Johnson
                                                                                                      ABC LimitedCO
                                                                                                      JJ@ABC.com
                                                                                                      none
                                                                                                       good Morning how are you today? 
                                                                                                      
                                                                                                      09/09/2021 19:35:35
                                                                                                      1631216135
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      MMArks
                                                                                                      Mark
                                                                                                      Marks
                                                                                                      XYZ Corp
                                                                                                      mm@xyz.com
                                                                                                      
                                                                                                       what time is it? 
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      

                                                                                                      The following blocks of code are what I have tried so far;

                                                                                                      import xml.etree.ElementTree as ET
                                                                                                      mytree = ET.parse(r'sample.xml')
                                                                                                      myroot = mytree.getroot()
                                                                                                      
                                                                                                      
                                                                                                      for content in myroot.iter('Content'):
                                                                                                          for name in myroot.iter('CompanyName'):
                                                                                                              cname = name
                                                                                                          output = content
                                                                                                          print(name.text, output.text)
                                                                                                      

                                                                                                      #This script will return:

                                                                                                      XYZ Corp good Morning how are you today? XYZ Corp what time is it?

                                                                                                      first one should say ABC Limited

                                                                                                      #I then tried this:

                                                                                                      for content in myroot.findall('Conversation'):
                                                                                                           output = content.find('Content')
                                                                                                           FName = content.find('FirstName')
                                                                                                           LName = content.find('LastName')
                                                                                                           cont = content.find('CompanyName')
                                                                                                           print(cont, "\n", FName, LName, output)
                                                                                                      

                                                                                                      #This returns

                                                                                                      None None None None

                                                                                                      so it doesnt trigger an error, but when I ask to return the text within:

                                                                                                      for content in myroot.findall('Conversation'):
                                                                                                           output = content.find('Content').text
                                                                                                           FName = content.find('FirstName').text
                                                                                                           LName = content.find('LastName').text
                                                                                                           cont = content.find('CompanyName').text
                                                                                                           print(cont, "\n", FName, LName, output)
                                                                                                      

                                                                                                      #This returns an error "'NoneType' object has no attribute 'text'" - even though there clearly is text I dont understand why its failing

                                                                                                      #But weirdly the above block of code works exactly as I want it to when I use the following XML script that I got from the ElementTree documentation, which I have edited to add the tags I am looking for in the real script, the XML code that isnt working has been validated as correct XML so I have ruled out any errors there - I dont know enough about xml to spot the difference and understand why its not working:

                                                                                                      (this works when combined with the last block of code:

                                                                                                      
                                                                                                      
                                                                                                          
                                                                                                              1
                                                                                                              2008
                                                                                                              141100
                                                                                                              
                                                                                                              
                                                                                                              John
                                                                                                              Johnson
                                                                                                              ABC LIMITED
                                                                                                              
                                                                                                             Good Morning How are you?
                                                                                                              
                                                                                                          
                                                                                                          
                                                                                                              4
                                                                                                              2011
                                                                                                              59900
                                                                                                              
                                                                                                              Mark
                                                                                                              Marks
                                                                                                              XYZ Corp
                                                                                                              
                                                                                                              Good Morning
                                                                                                              
                                                                                                          
                                                                                                          
                                                                                                              68
                                                                                                              2011
                                                                                                              13600
                                                                                                              
                                                                                                              
                                                                                                              Keith
                                                                                                              Keitherson
                                                                                                              WW Corp
                                                                                                              
                                                                                                           Good Evening 
                                                                                                              
                                                                                                          
                                                                                                      
                                                                                                      

                                                                                                      and it returns the following result:

                                                                                                      ABC LIMITED John Johnson Good Morning How are you?

                                                                                                      XYZ Corp Mark Marks Good Morning

                                                                                                      WW Corp Keith Keitherson Good Evening

                                                                                                      other things I have tried are:

                                                                                                      for content in myroot.itertext():
                                                                                                          print(content)
                                                                                                      

                                                                                                      #This does return all of the available text in the document, but doesnt take an arguement to narrow down my search for the tags I need

                                                                                                      As you can probably tell I am a coding noob and im trying to wing my way through this to solve a problem that has arisen.

                                                                                                      I have no doubt that its a very simple and basic change that I need to make, but from my lack of knowledge combined with the vast amount of different ways that this can be done online I have confused myself and now find myself here.

                                                                                                      I have tried to give as much info as possible, so anyone in the know should be able to point me in the right direction.

                                                                                                      If there is anymore info needed please let me know

                                                                                                      EDIT:

                                                                                                      The desired output is as follows:

                                                                                                      ABC LIMITED John Johnson good Morning how are you today?

                                                                                                      XYZ Corp Mark Marks what time is it?

                                                                                                      following the first suggestion the latest script I am using now is:

                                                                                                      for content in myroot.findall('.//Conversation'):
                                                                                                           output = content.find('.//Content').text
                                                                                                           FName = content.find('.//FirstName').text
                                                                                                           LName = content.find('.//LastName').text
                                                                                                           cont = content.find('.//CompanyName').text
                                                                                                           print(cont, "\n", FName, LName, output)
                                                                                                      

                                                                                                      This returns just one (the first) result from the specified tags as such:

                                                                                                      ABC LimitedCO John Johnson good Morning how are you today?

                                                                                                      EDIT:

                                                                                                      I have had mixed success with answers I have received, the suggestion wont work perfectly on this block of XML:

                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      1.3
                                                                                                      
                                                                                                      CHAT
                                                                                                      09/09/2021 19:35:35
                                                                                                      1631216135
                                                                                                      
                                                                                                      
                                                                                                      JJohnson
                                                                                                      JOHN
                                                                                                      Johnson
                                                                                                      ABC Limited CO
                                                                                                      JJ@abc.com
                                                                                                      
                                                                                                      
                                                                                                      09/09/2021 19:35:35
                                                                                                      1631216135
                                                                                                      
                                                                                                      Testing Content 1 
                                                                                                      
                                                                                                      CHAT
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      MMarks
                                                                                                      Mark
                                                                                                      MArks
                                                                                                      XYZ Corp
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      09/09/2021 19:35:35
                                                                                                      1631216135
                                                                                                      
                                                                                                      Testing content 2
                                                                                                      
                                                                                                      CHAT
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      SSamson
                                                                                                      Sam
                                                                                                      Samson
                                                                                                      123 CorpCO
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      Testing content 3
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      

                                                                                                      This returns:

                                                                                                      ABC Limited CO Johnson JOHN not_found XYZ Corp MArks Mark not_found 123 CorpCO Samson Sam Testing content 3

                                                                                                      ANSWER

                                                                                                      Answered 2021-Sep-16 at 15:34

                                                                                                      it looks like the below is what you are looking for

                                                                                                      import xml.etree.ElementTree as ET
                                                                                                      
                                                                                                      xml = '''
                                                                                                      
                                                                                                         1.3
                                                                                                         
                                                                                                            CHAT
                                                                                                            09/09/2021 19:35:35
                                                                                                            1631216135
                                                                                                            
                                                                                                               
                                                                                                                  JJohnson
                                                                                                                  JOHN
                                                                                                                  Johnson
                                                                                                                  ABC Limited CO
                                                                                                                  JJ@abc.com
                                                                                                                  
                                                                                                               
                                                                                                               09/09/2021 19:35:35
                                                                                                               1631216135
                                                                                                               Testing Content 1
                                                                                                               CHAT
                                                                                                            
                                                                                                            
                                                                                                               
                                                                                                                  MMarks
                                                                                                                  Mark
                                                                                                                  MArks
                                                                                                                  XYZ Corp
                                                                                                                  
                                                                                                                  
                                                                                                               
                                                                                                               09/09/2021 19:35:35
                                                                                                               1631216135
                                                                                                               Testing content 2
                                                                                                               CHAT
                                                                                                            
                                                                                                            
                                                                                                               
                                                                                                                  SSamson
                                                                                                                  Sam
                                                                                                                  Samson
                                                                                                                  123 CorpCO
                                                                                                                  
                                                                                                                  
                                                                                                                  Testing content 3
                                                                                                               
                                                                                                            
                                                                                                         
                                                                                                      
                                                                                                      '''
                                                                                                      
                                                                                                      NOT_FOUND = '__NOT_FOUND__'
                                                                                                      
                                                                                                      
                                                                                                      def _get(ele, name):
                                                                                                          sub = ele.find(name)
                                                                                                          return sub.text if sub is not None else NOT_FOUND
                                                                                                      
                                                                                                      
                                                                                                      root = ET.fromstring(xml)
                                                                                                      elements = ['CompanyName', 'LoginName', 'FirstName', 'Content']
                                                                                                      
                                                                                                      
                                                                                                      def loop(base_ele):
                                                                                                          for pe in root.findall(f'.//{base_ele}'):
                                                                                                              content = _get(pe, 'Content')
                                                                                                              u = pe.find('User')
                                                                                                              data = [_get(u, x) for x in elements] if content == NOT_FOUND else [_get(u, x) for x in elements[:-1]]
                                                                                                              if len(data) < 4:
                                                                                                                  data.append(content)
                                                                                                              msg = ' '.join(data)
                                                                                                              print(f"{msg}")
                                                                                                      
                                                                                                      
                                                                                                      loop('ParticipantEntered')
                                                                                                      loop('Message')
                                                                                                      

                                                                                                      output

                                                                                                      ABC Limited CO JJohnson JOHN Testing Content 1
                                                                                                      123 CorpCO SSamson Sam Testing content 3
                                                                                                      XYZ Corp MMarks Mark Testing content 2
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/69206889

                                                                                                      QUESTION

                                                                                                      Nokogiri & returning all data between two tags
                                                                                                      Asked 2021-Aug-30 at 12:47

                                                                                                      I'm working on a project that scrapes the items from https://platinumgod.co.uk/ & I'm having a hard time accessing all the

                                                                                                      tags between two elements.

                                                                                                      Here is the HTML:

                                                                                                      What I'm trying to do is return all of the

                                                                                                      tags between

                                                                                                      (excluding this tag) & the first

                                                                                                        .

                                                                                                        I've tried several solutions found on the forums & have only had partial success with using the following code that I found in one of the answers (not going to lie, I'm having a hard time understanding what's going on here). The reason I'm iterating is because there are several items in the HTML that need scraped:

                                                                                                      items = html.at(".repentanceitems-container").css("li.textbox").each do |item|
                                                                                                        use = item.xpath(".//a/span/p[5]/following-sibling::p[count(.//a/span/p[6]/preceding-sibling::p)= 
                                                                                                              count(.//a/span/p[6]/preceding-sibling::p)]")
                                                                                                        end
                                                                                                      

                                                                                                      However this only returns the first

                                                                                                      tag after

                                                                                                      . I'm sure it's probably something simple causing it since I don't understand the code. I have also accessed the first

                                                                                                      element I want to include & the

                                                                                                        where it needs to end but I'm not sure exactly how to use this info:

                                                                                                      # First line of item use
                                                                                                      start = item.xpath('.//a/span/p[5]')
                                                                                                      # ul tag
                                                                                                      ending = item.xpath('.//a/span/ul[1]')
                                                                                                      

                                                                                                      Any help with this would be much appreciated!

                                                                                                      ANSWER

                                                                                                      Answered 2021-Aug-26 at 02:58

                                                                                                      How about:

                                                                                                      The ~ syntax selects the current and further sibling elements, so I use a slice to skip the first element. I'm assuming .tags is the only other class to omit after .quality; if there are other elements besides this, you'll need to :not them as well, or manually detect and skip them in an .each loop, unless someone knows a cleverer trick.

                                                                                                      Source https://stackoverflow.com/questions/68931700

                                                                                                      QUESTION

                                                                                                      how to display cities in one dropdown based on selected state in other dropdown using json data in angular ionic?
                                                                                                      Asked 2021-Apr-27 at 16:44

                                                                                                      following are my files for html, .ts and json . As json data was very extensive therefore i have just added a few states and their cities. my 1st dropdown is showing all states. Now I want to match my 1st dropdown's selected value of state with a key "state" in "cities" object in my json file so i can populate 2nd dropdown with cities relevant to that state. and I want to do this in function "getCitiesForSelectedState". please help me find solution for this.

                                                                                                      //.ts file

                                                                                                      //json for states and cities
                                                                                                      import {StatesCities} from '../../../assets/states-cities/data';
                                                                                                      .
                                                                                                      .
                                                                                                      .
                                                                                                      states: any=[];
                                                                                                      cities: any=[];
                                                                                                      .
                                                                                                      .
                                                                                                       ngOnInit() {
                                                                                                      
                                                                                                      
                                                                                                          console.log(StatesCities.states);
                                                                                                          this.states=StatesCities.states;
                                                                                                        }
                                                                                                      .
                                                                                                      .
                                                                                                      .
                                                                                                      getCitiesForSelectedState(val){
                                                                                                      // I WANT TO POPULATE cities[] HERE ON MATCH OF "val" TO KEY IN JSON
                                                                                                      }
                                                                                                      

                                                                                                      //html file

                                                                                                      
                                                                                                              
                                                                                                                
                                                                                                                  State
                                                                                                                  
                                                                                                                    
                                                                                                                      {{s}}
                                                                                                                  
                                                                                                                
                                                                                                              
                                                                                                            
                                                                                                      
                                                                                                            
                                                                                                              
                                                                                                                
                                                                                                                  City
                                                                                                                  
                                                                                                                    
                                                                                                                      {{c}}
                                                                                                                  
                                                                                                                
                                                                                                              
                                                                                                            
                                                                                                      

                                                                                                      //json file

                                                                                                      export const StatesCities = {
                                                                                                          "states":["Alabama","Alaska","American Samoa","Arizona","Arkansas"  
                                                                                                        ],
                                                                                                        "city":[
                                                                                                          {
                                                                                                            "state":"Alabama",
                                                                                                            "cities":[
                                                                                                            "ABBEVILLE", "ADAMSVILLE", "ADDISON", "AKRON", "ALABASTER", "ALBERTVILLE",
                                                                                                             "ALEXANDER CITY", "ALEXANDRIA", "ALICEVILLE", "ALLGOOD", "ALTOONA", "ANDALUSIA",
                                                                                                             "ANDERSON", "ANNISTON", "ARAB", "ARDMORE", "ARGO", "ARITON", "ARLEY", "ASHFORD", "ASHLAND",
                                                                                                             "ASHVILLE", "ATHENS", "ATMORE", "ATTALLA", "AUBURN", "AUTAUGAVILLE", "AVON", "BABBIE", "BAILEYTON",
                                                                                                             "BANKS", "BAY MINETTE", "BAYOU LA BATRE", "BEAR CREEK", "BEATRICE", "BEAVERTON", "BELK", "BENTON",
                                                                                                             "BERRY", "BESSEMER", "BILLINGSLEY", "BIRMINGHAM", "BLACK", "BLOUNTSVILLE", "BLUE MOUNTAIN", "BLUE RIDGE ",
                                                                                                             "BLUE SPRINGS ", "BOAZ ", "BOLIGEE ", "BON AIR ", " BRANCHVILLE ", "BRANTLEY ", " BRENT ", " BREWTON ",
                                                                                                             "BRIDGEPORT", "BRIGHTON", "BRILLIANT", "BROOKSIDE", "BROOKWOOD", "BRUNDIDGE", "BUTLER", "BYNUM",
                                                                                                             "CAHABA HEIGHTS", "CALERA", "CAMDEN", "CAMP HILL", "CARBON HILL", "CARDIFF", "CAROLINA",
                                                                                                             "CARROLLTON", "CASTLEBERRY", "CEDAR BLUFF", "CENTER POINT", "CENTRE", "CENTREVILLE", "CHALKVILLE",
                                                                                                             "CHATOM", "CHELSEA", "CHEROKEE", "CHICKASAW", "CHILDERSBURG", "CITRONELLE", "CLANTON", "CLAY",
                                                                                                             "CLAYHATCHEE", "CLAYTON", "CLEVELAND", "CLIO", "COALING", "COFFEE SPRINGS", "COFFEEVILLE",
                                                                                                             "COKER", "COLLINSVILLE", "COLONY", "COLUMBIA", "COLUMBIANA", "CONCORD", "COOSADA", "CORDOVA",
                                                                                                             "COTTONWOOD", "COUNTY LINE", "COURTLAND", "COWARTS", "CREOLA", "CROSSVILLE", "CUBA", "CULLMAN",
                                                                                                             "DADEVILLE", "DALEVILLE", "DAPHNE", "DAUPHIN ISLAND", "DAVISTON", "DAYTON", "DEATSVILLE", "DECATUR",
                                                                                                             "DEMOPOLIS", "DETROIT", "DODGE CITY", "DORA", "DOTHAN", "DOUBLE SPRINGS", "DOUGLAS", "DOZIER", "DUTTON",
                                                                                                             "EAST BREWTON", "ECLECTIC", "EDGEWATER", "EDWARDSVILLE", "ELBA", "ELBERTA", "ELDRIDGE", "ELKMONT", "ELMORE",
                                                                                                             "EMELLE", "ENTERPRISE", "EPES", "ETHELSVILLE", "EUFAULA", "EUNOLA", "EUTAW", "EVA", "EVERGREEN", "EXCEL",
                                                                                                             "FAIRFIELD", "FAIRHOPE", "FAIRVIEW", "FALKVILLE", "FAUNSDALE", "FAYETTE", "FIVE POINTS", "FLOMATON",
                                                                                                             "FLORALA", "FLORENCE", "FOLEY", "FORESTDALE", "FORKLAND", "FORT DEPOSIT", "FORT PAYNE", "FORT RUCKER",
                                                                                                             "FRANKLIN", "FRISCO CITY", "FRUITHURST", "FULTON", "FULTONDALE", "FYFFE", "GADSDEN", "GAINESVILLE", "GANTT",
                                                                                                             "GANTTS QUARRY", "GARDEN CITY", "GARDENDALE", "GAYLESVILLE", "GEIGER", "GENEVA", "GEORGIANA", "GERALDINE",
                                                                                                             "GILBERTOWN", "GLEN ALLEN", "GLENCOE", "GLENWOOD", "GOLDVILLE", "GOOD HOPE", "GOODWATER", "GORDO", "GORDON",
                                                                                                             "GORDONVILLE", "GOSHEN", "GRAND BAY", "GRANT", "GRAYSON VALLEY", "GRAYSVILLE", "GREENSBORO", "GREENVILLE",
                                                                                                             "GRIMES", "GROVE HILL", "GUIN", "GULF SHORES", "GUNTERSVILLE", "GURLEY", "GU-WIN", "HACKLEBURG", "HALEBURG",
                                                                                                             "HALEYVILLE", "HAMILTON", "HAMMONDVILLE", "HANCEVILLE", "HARPERSVILLE", "HARTFORD", "HARTSELLE", "HARVEST",
                                                                                                             "HAYDEN", "HAYNEVILLE", "HAZEL GREEN", "HEADLAND", "HEATH", "HEFLIN", "HELENA", "HENAGAR", "HIGHLAND LAKE",
                                                                                                             "HILLSBORO", "HOBSON CITY", "HODGES", "HOKES BLUFF", "HOLLY POND", "HOLLYWOOD", "HOLT", "HOMEWOOD", "HOOVER",
                                                                                                             "HORN HILL", "HUEYTOWN", "HUGULEY", "HUNTSVILLE", "HURTSBORO", "HYTOP", "IDER", "INDIAN SPRINGS VILLAGE", "IRONDALE",
                                                                                                             "JACKSON", "JACKSONS GAP", "JACKSONVILLE", "JASPER", "JEMISON", "KANSAS", "KENNEDY", "KILLEN", "KIMBERLY", "KINSEY",
                                                                                                             "KINSTON", "LADONIA", "LA FAYETTE", "LAKE PURDY", "LAKEVIEW", "LAKE VIEW", "LANETT", "LANGSTON", "LEEDS", "LEESBURG",
                                                                                                             "LEIGHTON", "LESTER", "LEVEL PLAINS", "LEXINGTON", "LIBERTYVILLE", "LINCOLN", "LINDEN", "LINEVILLE", "LIPSCOMB",
                                                                                                             "LISMAN", "LITTLEVILLE", "LIVINGSTON", "LOACHAPOKA", "LOCKHART", "LOCUST FORK", "LOUISVILLE", "LOWNDESBORO",
                                                                                                             "LOXLEY", "LUVERNE", "LYNN", "MCDONALD CHAPEL", "MACEDONIA", "MCINTOSH", "MCKENZIE", "MCMULLEN", "MADISON", "MADRID",
                                                                                                             "MALVERN", "MAPLESVILLE", "MARGARET", "MARION", "MAYTOWN", "MEADOWBROOK", "MEMPHIS", "MENTONE", "MERIDIANVILLE", "MIDFIELD",
                                                                                                             "MIDLAND CITY", "MIDWAY", "MIGNON", "MILLBROOK", "MILLPORT", "MILLRY", "MINOR", "MOBILE", "MONROEVILLE", "MONTEVALLO", "MONTGOMERY",
                                                                                                             "MOODY", "MOORES MILL", "MOORESVILLE", "MORRIS", "MOSSES", "MOULTON", "MOUNDVILLE", "MOUNTAINBORO", "MOUNTAIN BROOK", "MOUNT OLIVE",
                                                                                                             "MOUNT VERNON", "MULGA", "MUNFORD", "MUSCLE SHOALS", "MYRTLEWOOD", "NAPIER FIELD", "NATURAL BRIDGE", "NAUVOO", "NECTAR", "NEEDHAM",
                                                                                                             "NEWBERN", "NEW BROCKTON", "NEW HOPE", "NEW MARKET", "NEW SITE", "NEWTON", "NEWVILLE", "NORTH BIBB", "NORTH COURTLAND", "NORTH JOHNS",
                                                                                                             "NORTHPORT", "NOTASULGA", "OAK GROVE", "OAK HILL", "OAKMAN", "ODENVILLE", "OHATCHEE", "ONEONTA", "ONYCHA", "OPELIKA", "OPP", "ORANGE BEACH",
                                                                                                             "ORRVILLE", "OWENS CROSS ROADS", "OXFORD", "OZARK", "PAINT ROCK", "PARRISH", "PELHAM", "PELL CITY", "PENNINGTON", "PETREY", "PHENIX CITY",
                                                                                                             "PHIL CAMPBELL", "PICKENSVILLE", "PIEDMONT", "PIKE ROAD", "PINCKARD", "PINE APPLE", "PINE HILL", "PINE RIDGE", "PINSON", "PISGAH",
                                                                                                             "PLEASANT GROVE", "PLEASANT GROVES", "POINT CLEAR", "POLLARD", "POWELL", "PRATTVILLE", "PRICEVILLE", "PRICHARD", "PROVIDENCE",
                                                                                                             "RAGLAND", "RAINBOW CITY", "RAINSVILLE", "RANBURNE", "RED BAY", "RED LEVEL", "REDSTONE ARSENAL", "REECE CITY", "REFORM", "REHOBETH",
                                                                                                             "REPTON", "RIDGEVILLE", "RIVER FALLS", "RIVERSIDE", "RIVERVIEW", "ROANOKE", "ROBERTSDALE", "ROCK CREEK", "ROCKFORD", "ROCK MILLS",
                                                                                                             "ROGERSVILLE", "ROSA", "RUSSELLVILLE", "RUTLEDGE", "ST. FLORIAN", "SAKS", "SAMSON", "SAND ROCK", "SANFORD", "SARALAND", "SARDIS CITY",
                                                                                                             "SATSUMA", "SCOTTSBORO", "SECTION", "SELMA", "SELMONT-WEST SELMONT", "SHEFFIELD", "SHILOH", "SHORTER", "SILAS", "SILVERHILL", "SIPSEY",
                                                                                                             "SKYLINE", "SLOCOMB", "SMITHS", "SMOKE RISE", "SNEAD", "SOMERVILLE", "SOUTHSIDE", "SOUTH VINEMONT", "SPANISH FORT", "SPRINGVILLE", "STEELE",
                                                                                                             "STEVENSON", "SULLIGENT", "SUMITON", "SUMMERDALE", "SUSAN MOORE", "SWEET WATER", "SYLACAUGA", "SYLVANIA", "SYLVAN SPRINGS", "TALLADEGA",
                                                                                                             "TALLADEGA SPRINGS", "TALLASSEE", "TARRANT", "TAYLOR", "THEODORE", "THOMASTON", "THOMASVILLE", "THORSBY", "TILLMANS CORNER", "TOWN CREEK",
                                                                                                             "TOXEY", "TRAFFORD", "TRIANA", "TRINITY", "TROY", "TRUSSVILLE", "TUSCALOOSA", "TUSCUMBIA", "TUSKEGEE", "UNDERWOOD-PETERSVILLE", "UNION",
                                                                                                             "UNION GROVE", "UNION SPRINGS", "UNIONTOWN", "VALLEY", "VALLEY HEAD", "VANCE", "VERNON", "VESTAVIA HILLS", "VINA", "VINCENT", "VREDENBURGH",
                                                                                                             "WADLEY", "WALDO", "WALNUT GROVE", "WARRIOR", "WATERLOO", "WAVERLY", "WEAVER", "WEBB", "WEDOWEE", "WEST BLOCTON", "WEST END-COBB TOWN",
                                                                                                             "WEST JEFFERSON", "WEST POINT", "WETUMPKA", "WHITE HALL", "WILSONVILLE", "WILTON", "WINFIELD", "WOODLAND", "WOODVILLE", "YELLOW BLUFF", "YORK"
                                                                                                           ]
                                                                                                          },
                                                                                                          {
                                                                                                            "state":"Alaska",
                                                                                                            "cities": ["ADAK", "AKHIOK", "AKIACHAK", "AKIAK", "AKUTAN", "ALAKANUK", "ALATNA", "ALCAN BORDER", "ALEKNAGIK", "ALENEVA", "ALLAKAKET", "ALPINE", "AMBLER",
                                                                                                            "ANAKTUVUK PASS", "ANCHORAGE", "ANCHOR POINT", "ANDERSON", "ANGOON", "ANIAK", "ANVIK", "ARCTIC VILLAGE", "ATKA", "ATMAUTLUAK", "ATQASUK", "ATTU STATION",
                                                                                                            "BARROW", "BEAR CREEK", "BEAVER", "BELUGA", "BETHEL", "BETTLES", "BIG DELTA", "BIG LAKE", "BIRCH CREEK", "BREVIG MISSION", "BUCKLAND", "BUFFALO SOAPSTONE",
                                                                                                            "BUTTE", "CANTWELL", "CENTRAL", "CHALKYITSIK", "CHASE", "CHEFORNAK", "CHENEGA", "CHEVAK", "CHICKALOON", "CHICKEN", "CHIGNIK", "CHIGNIK LAGOON", "CHIGNIK LAKE",
                                                                                                            "CHINIAK", "CHISANA", "CHISTOCHINA", "CHITINA", "CHUATHBALUK", "CIRCLE", "CLAM GULCH", "CLARK S POINT", "COFFMAN COVE", "COHOE", "COLD BAY", "COLDFOOT",
                                                                                                            "COLLEGE", "COOPER LANDING", "COPPER CENTER", "COPPERVILLE", "CORDOVA", "COVENANT LIFE", "CRAIG", "CROOKED CREEK", "CROWN POINT", "CUBE COVE", "DEERING",
                                                                                                            "DELTA JUNCTION", "DELTANA", "DIAMOND RIDGE", "DILLINGHAM", "DIOMEDE", "DOT LAKE", "DOT LAKE VILLAGE", "DRY CREEK", "EAGLE", "EAGLE VILLAGE", "EDNA BAY",
                                                                                                            "EEK", "EGEGIK", "EIELSON AFB", "EKWOK", "ELFIN COVE", "ELIM", "EMMONAK", "ESTER", "EVANSVILLE", "EXCURSION INLET", "FAIRBANKS", "FALSE PASS", "FARM LOOP",
                                                                                                            "FERRY", "FISHHOOK", "FLAT", "FORT GREELY", "FORT YUKON", "FOUR MILE ROAD", "FOX", "FOX RIVER", "FRITZ CREEK", "FUNNY RIVER", "GAKONA", "GALENA", "GAMBELL",
                                                                                                            "GAME CREEK", "GATEWAY", "GLACIER VIEW", "GLENNALLEN", "GOLOVIN", "GOODNEWS BAY", "GRAYLING", "GULKANA", "GUSTAVUS", "HAINES", "HALIBUT COVE", "HAPPY VALLEY",
                                                                                                            "HARDING-BIRCH LAKES", "HEALY", "HEALY LAKE", "HOBART BAY", "HOLLIS", "HOLY CROSS", "HOMER", "HOONAH", "HOOPER BAY", "HOPE", "HOUSTON", "HUGHES", "HUSLIA",
                                                                                                            "HYDABURG", "HYDER", "IGIUGIG", "ILIAMNA", "IVANOF BAY", "JUNEAU CITY AND", "KACHEMAK", "KAKE", "KAKTOVIK", "KALIFORNSKY", "KALTAG", "KARLUK", "KASAAN",
                                                                                                            "KASIGLUK", "KASILOF", "KENAI", "KENNY LAKE", "KETCHIKAN", "KIANA", "KING COVE", "KING SALMON", "KIPNUK", "KIVALINA", "KLAWOCK", "KLUKWAN", "KNIK-FAIRVIEW",
                                                                                                            "KNIK RIVER", "KOBUK", "KODIAK", "KODIAK STATION", "KOKHANOK", "KOLIGANEK", "KONGIGANAK", "KOTLIK", "KOTZEBUE", "KOYUK", "KOYUKUK", "KUPREANOF", "KWETHLUK",
                                                                                                            "KWIGILLINGOK", "LAKE LOUISE", "LAKE MINCHUMINA", "LAKES", "LARSEN BAY", "LAZY MOUNTAIN", "LEVELOCK", "LIME VILLAGE", "LIVENGOOD", "LOWELL POINT",
                                                                                                            "LOWER KALSKAG", "LUTAK", "MCCARTHY", "MCGRATH", "MCKINLEY PARK", "MANLEY HOT SPRINGS", "MANOKOTAK", "MARSHALL", "MEADOW LAKES", "MEKORYUK", "MENDELTNA",
                                                                                                            "MENTASTA LAKE", "METLAKATLA", "MEYERS CHUCK", "MILLER LANDING", "MINTO", "MOOSE CREEK", "MOOSE PASS", "MOSQUITO LAKE", "MOUNTAIN VILLAGE", "MUD BAY",
                                                                                                            "NAKNEK", "NANWALEK", "NAPAKIAK", "NAPASKIAK", "NAUKATI BAY", "NELCHINA", "NELSON LAGOON", "NENANA", "NEW ALLAKAKET", "NEWHALEN", "NEW STUYAHOK", "NEWTOK",
                                                                                                            "NIGHTMUTE", "NIKISKI", "NIKOLAEVSK", "NIKOLAI", "NIKOLSKI", "NINILCHIK", "NOATAK", "NOME", "NONDALTON", "NOORVIK", "NORTH POLE", "NORTHWAY",
                                                                                                            "NORTHWAY JUNCTION", "NORTHWAY VILLAGE", "NUIQSUT", "NULATO", "NUNAPITCHUK", "OLD HARBOR", "OSCARVILLE", "OUZINKIE", "PALMER", "PAXSON", "PEDRO BAY",
                                                                                                            "PELICAN", "PERRYVILLE", "PETERSBURG", "PETERSVILLE", "PILOT POINT", "PILOT STATION", "PITKAS POINT", "PLATINUM", "PLEASANT VALLEY", "POINT BAKER",
                                                                                                            "POINT HOPE", "POINT LAY", "POINT MACKENZIE", "POPE-VANNOY LANDING", "PORTAGE CREEK", "PORT ALEXANDER", "PORT ALSWORTH", "PORT CLARENCE", "PORT GRAHAM",
                                                                                                            "PORT HEIDEN", "PORT LIONS", "PORT PROTECTION", "PRIMROSE", "PRUDHOE BAY", "QUINHAGAK", "RAMPART", "RED DEVIL", "RED DOG MINE", "RIDGEWAY", "RUBY",
                                                                                                            "RUSSIAN MISSION", "ST. GEORGE", "ST. MARYS", "ST. MICHAEL", "ST. PAUL", "SALAMATOF", "SALCHA", "SAND POINT", "SAVOONGA", "SAXMAN", "SCAMMON BAY",
                                                                                                            "SELAWIK", "SELDOVIA", "SELDOVIA VILLAGE", "SEWARD", "SHAGELUK", "SHAKTOOLIK", "SHELDON POINT (NUNAM IQUA)", "SHISHMAREF", "SHUNGNAK", "SILVER SPRINGS",
                                                                                                            "SITKA CITY AND", "SKAGWAY", "SKWENTNA", "SLANA", "SLEETMUTE", "SOLDOTNA", "SOUTH NAKNEK", "STEBBINS", "STERLING", "STEVENS VILLAGE", "STONY RIVER",
                                                                                                            "SUNRISE", "SUSITNA", "SUTTON-ALPINE", "TAKOTNA", "TALKEETNA", "TANACROSS", "TANAINA", "TANANA", "TATITLEK", "TAZLINA", "TELLER", "TENAKEE SPRINGS",
                                                                                                            "TETLIN", "THOMS PLACE", "THORNE BAY", "TOGIAK", "TOK", "TOKSOOK BAY", "TOLSONA", "TONSINA", "TRAPPER CREEK", "TULUKSAK", "TUNTUTULIAK", "TUNUNAK",
                                                                                                            "TWIN HILLS", "TWO RIVERS", "TYONEK", "UGASHIK", "UNALAKLEET", "UNALASKA", "UPPER KALSKAG", "VALDEZ", "VENETIE", "WAINWRIGHT", "WALES", "WASILLA",
                                                                                                            "WHALE PASS", "WHITE MOUNTAIN", "WHITESTONE LOGGING CAMP", "WHITTIER", "WILLOW", "WILLOW CREEK", "WISEMAN", "WOMENS BAY", "WRANGELL", "Y", "YAKUTAT"
                                                                                                          ]
                                                                                                          },
                                                                                                          {
                                                                                                            "state":"Arizona",
                                                                                                            "cities":["American Samoa"]
                                                                                                          },
                                                                                                          {
                                                                                                            "state":"American Samoa",
                                                                                                            "cities":["AJO", "AK-CHIN VILLAGE", "AMADO", "APACHE JUNCTION", "ARI", "ARI", "ASH FORK", "AVONDALE", "AVRA VALLEY", "BAGDAD", "BENSON", "BIG PARK", "BISBEE",
                                                                                                            "BITTER SPRINGS", "BLACK CANYON CITY", "BLACKWATER", "BLUEWATER", "BOUSE", "BUCKEYE", "BULLHEAD CITY", "BURNSIDE", "CAMERON", "CAMP VERDE", "CANYON DAY",
                                                                                                            "CAREFREE", "CASA GRANDE", "CASAS ADOBES", "CATALINA", "CATALINA FOOTHILLS", "CAVE CREEK", "CENTRAL HEIGHTS-MIDLAND CITY", "CHANDLER", "CHILCHINBITO",
                                                                                                            "CHINLE", "CHINO VALLEY", "CHUICHU", "CIBECUE", "CIBOLA", "CLARKDALE", "CLAYPOOL", "CLIFTON", "COLORADO CITY", "CONGRESS", "COOLIDGE", "CORDES LAKES",
                                                                                                            "CORNVILLE", "CORONA DE TUCSON", "COTTONWOOD", "COTTONWOOD-VERDE VILLAGE", "DENNEHOTSO", "DESERT HILLS", "DEWEY-HUMBOLDT", "DILKON", "DOLAN SPRINGS",
                                                                                                            "DOUGLAS", "DREXEL-ALVERNON", "DREXEL HEIGHTS", "DUDLEYVILLE", "DUNCAN", "EAGAR", "EAST FORK", "EAST SAHUARITA", "EHRENBERG", "ELGIN", "EL MIRAGE", "ELOY",
                                                                                                            "FIRST MESA", "FLAGSTAFF", "FLORENCE", "FLOWING WELLS", "FORT DEFIANCE", "FORTUNA FOOTHILLS", "FOUNTAIN HILLS", "FREDONIA", "GADSDEN", "GANADO", "GILA BEND",
                                                                                                            "GILBERT", "GISELA", "GLENDALE", "GLOBE", "GOLD CAMP", "GOLDEN VALLEY", "GOODYEAR", "GRAND CANYON VILLAGE", "GREASEWOOD", "GREEN VALLEY", "GUADALUPE", "HAYDEN",
                                                                                                            "HEBER-OVERGAARD", "HOLBROOK", "HOTEVILLA-BACAVI", "HOUCK", "HUACHUCA CITY", "JEDDITO", "JEROME", "KACHINA VILLAGE", "KAIBAB", "KAIBITO", "KAYENTA",
                                                                                                            "KEAMS CANYON", "KEARNY", "KINGMAN", "KYKOTSMOVI VILLAGE", "LAKE HAVASU CITY", "LAKE MONTEZUMA", "LECHEE", "LEUPP", "LITCHFIELD PARK", "LITTLETOWN",
                                                                                                            "LUKACHUKAI", "MCNARY", "MAMMOTH", "MANY FARMS", "MARANA", "MARICOPA", "MAYER", "MESA", "MESQUITE CREEK", "MIAMI", "MOENKOPI", "MOHAVE VALLEY",
                                                                                                            "MOJAVE RANCH ESTATES", "MORENCI", "MOUNTAINAIRE", "MUNDS PARK", "NACO", "NAZLINI", "NEW KINGMAN-BUTLER", "NEW RIVER", "NOGALES",
                                                                                                            "OLJATO-MONUMENT VALLEY", "ORACLE", "ORO VALLEY", "PAGE", "PARADISE VALLEY", "PARKER", "PARKER STRIP", "PARKS", "PATAGONIA", "PAULDEN",
                                                                                                            "PAYSON", "PEACH SPRINGS", "PEEPLES VALLEY", "PEORIA", "PERIDOT", "PHOENIX", "PICTURE ROCKS", "PIMA", "PINE", "PINETOP-LAKESIDE", "PINON",
                                                                                                            "PIRTLEVILLE", "PISINEMO", "POSTON", "PRESCOTT", "PRESCOTT VALLEY", "QUARTZSITE", "QUEEN CREEK", "QUEEN VALLEY", "RED MESA", "RIO RICO NORTHEAST",
                                                                                                            "RIO RICO NORTHWEST", "RIO RICO SOUTHEAST", "RIO RICO SOUTHWEST", "RIO VERDE", "ROCK POINT", "ROUGH ROCK", "ROUND ROCK", "SACATON", "SAFFORD",
                                                                                                            "SAHUARITA", "ST. DAVID", "ST. JOHNS", "ST. MICHAELS", "SALOME", "SAN CARLOS", "SAN LUIS", "SAN MANUEL", "SANTAN", "SANTA ROSA", "SAWMILL",
                                                                                                            "SCOTTSDALE", "SECOND MESA", "SEDONA", "SELIGMAN", "SELLS", "SHONGOPOVI", "SHONTO", "SHOW LOW", "SIERRA VISTA", "SIERRA VISTA SOUTHEAST",
                                                                                                            "SNOWFLAKE", "SOMERTON", "SONOITA", "SOUTH TUCSON", "SPRINGERVILLE", "SPRING VALLEY", "STANFIELD", "STEAMBOAT", "STRAWBERRY", "SUMMIT",
                                                                                                            "SUN CITY", "SUN CITY WEST", "SUN LAKES", "SUN VALLEY", "SUPAI", "SUPERIOR", "SURPRISE", "SWIFT TRAIL JUNCTION", "TACNA", "TANQUE VERDE",
                                                                                                            "TAYLOR", "TEEC NOS POS", "TEMPE", "THATCHER", "THREE POINTS", "TOLLESON", "TOMBSTONE", "TONALEA", "TONTO BASIN", "TOP-OF-THE-WORLD",
                                                                                                            "TORTOLITA", "TSAILE", "TUBAC", "TUBA CITY", "TUCSON", "TUCSON ESTATES", "TUMACACORI-CARMEN", "TUSAYAN", "VAIL", "VALENCIA WEST", "WELLTON",
                                                                                                            "WENDEN", "WHETSTONE", "WHITERIVER", "WICKENBURG", "WILHOIT", "WILLCOX", "WILLIAMS", "WILLIAMSON", "WILLOW VALLEY", "WINDOW ROCK", "WINKELMAN",
                                                                                                            "WINSLOW", "WINSLOW WEST", "YARNELL", "YOUNG", "YOUNGTOWN", "YUMA"
                                                                                                          ]
                                                                                                          },
                                                                                                          {
                                                                                                            "state":"Arkansas",
                                                                                                            "cities": ["ADONA", "ALEXANDER", "ALICIA", "ALLPORT", "ALMA", "ALMYRA", "ALPENA", "ALTHEIMER", "ALTUS", "AMAGON", "AMITY", "ANTHONYVILLE", "ANTOINE", "ARKADELPHIA",
                                                                                                            "ARKANSAS CITY", "ASHDOWN", "ASH FLAT", "ATKINS", "AUBREY", "AUGUSTA", "AUSTIN", "AVOCA", "BALD KNOB", "BANKS", "BARLING", "BASSETT", "BATESVILLE", "BAUXITE",
                                                                                                            "BAY", "BEARDEN", "BEAVER", "BEEBE", "BEEDEVILLE", "BELLA VISTA", "BELLEFONTE", "BELLEVILLE", "BEN LOMOND", "BENTON", "BENTONVILLE", "BERGMAN", "BERRYVILLE",
                                                                                                            "BETHEL HEIGHTS", "BIGELOW", "BIG FLAT", "BIGGERS", "BIRDSONG", "BLACK OAK", "BLACK ROCK", "BLACK SPRINGS", "BLEVINS", "BLUE EYE", "BLUE MOUNTAIN",
                                                                                                            "BLUFF CITY", "BLYTHEVILLE", "BODCAW", "BONANZA", "BONO", "BOONEVILLE", "BRADFORD", "BRADLEY", "BRANCH", "BRIARCLIFF", "BRINKLEY", "BROOKLAND", "BRYANT",
                                                                                                            "BUCKNER", "BULL SHOALS", "BURDETTE", "CABOT", "CADDO VALLEY", "CALDWELL", "CALE", "CALICO ROCK", "CALION", "CAMDEN", "CAMMACK VILLAGE", "CAMPBELL STATION",
                                                                                                            "CARAWAY", "CARLISLE", "CARTHAGE", "CASA", "CASH", "CAULKSVILLE", "CAVE CITY", "CAVE SPRINGS", "CEDARVILLE", "CENTERTON", "CENTRAL CITY", "CHARLESTON",
                                                                                                            "CHEROKEE VILLAGE", "CHERRY VALLEY", "CHESTER", "CHIDESTER", "CLARENDON", "CLARKSVILLE", "CLINTON", "COAL HILL", "COLLEGE CITY", "COLLEGE STATION",
                                                                                                            "COLT", "CONCORD", "CONWAY", "CORINTH", "CORNING", "COTTER", "COTTON PLANT", "COVE", "COY", "CRAWFORDSVILLE", "CROSSETT", "CUSHMAN", "DAISY", "DAMASCUS",
                                                                                                            "DANVILLE", "DARDANELLE", "DATTO", "DECATUR", "DELAPLAINE", "DELIGHT", "DELL", "DENNING", "DE QUEEN", "DERMOTT", "DES ARC", "DE VALLS BLUFF", "DE WITT",
                                                                                                            "DIAMOND CITY", "DIAZ", "DIERKS", "DONALDSON", "DOVER", "DUMAS", "DYER", "DYESS", "EARLE", "EAST CAMDEN", "EAST END", "EDMONDSON", "EGYPT", "ELAINE",
                                                                                                            "EL DORADO", "ELKINS", "ELM SPRINGS", "EMERSON", "EMMET", "ENGLAND", "ENOLA", "ETOWAH", "EUDORA", "EUREKA SPRINGS", "EVENING SHADE", "EVERTON", "FAIRFIELD BAY",
                                                                                                            "FARGO", "FARMINGTON", "FAYETTEVILLE", "FELSENTHAL", "FIFTY-SIX", "FISHER", "FLIPPIN", "FORDYCE", "FOREMAN", "FORREST CITY", "FORT SMITH", "FOUKE",
                                                                                                            "FOUNTAIN HILL", "FOUNTAIN LAKE", "FOURCHE", "FRANKLIN", "FREDONIA (BISCOE)", "FRIENDSHIP", "FULTON", "GARFIELD", "GARLAND", "GARNER", "GASSVILLE",
                                                                                                            "GATEWAY", "GENTRY", "GEORGETOWN", "GIBSON", "GILBERT", "GILLETT", "GILLHAM", "GILMORE", "GLENWOOD", "GOSHEN", "GOSNELL", "GOULD", "GRADY", "GRANNIS",
                                                                                                            "GRAVEL RIDGE", "GRAVETTE", "GREENBRIER", "GREEN FOREST", "GREENLAND", "GREENWAY", "GREENWOOD", "GREERS FERRY", "GRIFFITHVILLE", "GRUBBS", "GUION",
                                                                                                            "GUM SPRINGS", "GURDON", "GUY", "HACKETT", "HAMBURG", "HAMPTON", "HARDY", "HARRELL", "HARRISBURG", "HARRISON", "HARTFORD", "HARTMAN", "HASKELL",
                                                                                                            "HATFIELD", "HAVANA", "HAYNES", "HAZEN", "HEBER SPRINGS", "HECTOR", "HELENA", "HENSLEY", "HERMITAGE", "HICKORY RIDGE", "HIGDEN", "HIGGINSON",
                                                                                                            "HIGHFILL", "HIGHLAND", "HINDSVILLE", "HOLLAND", "HOLLY GROVE", "HOPE", "HORATIO", "HORSESHOE BEND", "HORSESHOE LAKE", "HOT SPRINGS",
                                                                                                            "HOT SPRINGS VILLAGE", "HOUSTON", "HOXIE", "HUGHES", "HUMNOKE", "HUMPHREY", "HUNTER", "HUNTINGTON", "HUNTSVILLE", "HUTTIG", "IMBODEN",
                                                                                                            "JACKSONPORT", "JACKSONVILLE", "JASPER", "JENNETTE", "JERICHO", "JEROME", "JOHNSON", "JOINER", "JONESBORO", "JUDSONIA", "JUNCTION CITY",
                                                                                                            "KEISER", "KENSETT", "KEO", "KIBLER", "KINGSLAND", "KNOBEL", "KNOXVILLE", "LAFE", "LAGRANGE", "LAKE CITY", "LAKE HAMILTON", "LAKEVIEW",
                                                                                                            "LAKE VIEW", "LAKE VILLAGE", "LAMAR", "LAVACA", "LEACHVILLE", "LEAD HILL", "LEOLA", "LEPANTO", "LESLIE", "LETONA", "LEWISVILLE", "LEXA",
                                                                                                            "LINCOLN", "LITTLE FLOCK", "LITTLE ROCK", "LOCKESBURG", "LONDON", "LONOKE", "LONSDALE", "LOUANN", "LOWELL", "LUXORA", "LYNN", "MCALMONT",
                                                                                                            "MCCASKILL", "MCCRORY", "MCDOUGAL", "MCGEHEE", "MCNAB", "MCNEIL", "MCRAE", "MADISON", "MAGAZINE", "MAGNESS", "MAGNOLIA", "MALVERN", "MAMMOTH SPRING",
                                                                                                            "MANILA", "MANSFIELD", "MARIANNA", "MARIE", "MARION", "MARKED TREE", "MARMADUKE", "MARSHALL", "MARVELL", "MAUMELLE", "MAYFLOWER", "MAYNARD", "MELBOURNE",
                                                                                                            "MENA", "MENIFEE", "MIDLAND", "MINERAL SPRINGS", "MINTURN", "MITCHELLVILLE", "MONETTE", "MONTICELLO", "MONTROSE", "MOOREFIELD", "MORO", "MORRILTON",
                                                                                                            "MORRISON BLUFF", "MOUNTAINBURG", "MOUNTAIN HOME", "MOUNTAIN PINE", "MOUNTAIN VIEW", "MOUNT IDA", "MOUNT PLEASANT", "MOUNT VERNON", "MULBERRY",
                                                                                                            "MURFREESBORO", "NASHVILLE", "NEWARK", "NEWPORT", "NIMMONS", "NORFORK", "NORMAN", "NORPHLET", "NORTH CROSSETT", "NORTH LITTLE ROCK", "OAK GROVE",
                                                                                                            "OAK GROVE HEIGHTS", "OAKHAVEN", "ODEN", "OGDEN", "OIL TROUGH", "O KEAN", "OKOLONA", "OLA", "OMAHA", "OPPELO", "OSCEOLA", "OXFORD", "OZAN", "OZARK",
                                                                                                            "PALESTINE", "PANGBURN", "PARAGOULD", "PARIS", "PARKDALE", "PARKERS-IRON SPRINGS", "PARKIN", "PATMOS", "PATTERSON", "PEACH ORCHARD", "PEA RIDGE",
                                                                                                            "PERLA", "PERRY", "PERRYTOWN", "PERRYVILLE", "PIGGOTT", "PINDALL", "PINE BLUFF", "PINEVILLE", "PINEY", "PLAINVIEW", "PLEASANT PLAINS", "PLUMERVILLE",
                                                                                                            "POCAHONTAS", "POLLARD", "PORTIA", "PORTLAND", "POTTSVILLE", "POWHATAN", "POYEN", "PRAIRIE CREEK", "PRAIRIE GROVE", "PRATTSVILLE", "PRESCOTT", "PYATT",
                                                                                                            "QUITMAN", "RATCLIFF", "RAVENDEN", "RAVENDEN SPRINGS", "READER", "RECTOR", "REDFIELD", "REED", "REYNO", "RISON", "ROCKPORT", "ROCKWELL", "ROE", "ROGERS",
                                                                                                            "RONDO", "ROSE BUD", "ROSSTON", "RUDY", "RUSSELL", "RUSSELLVILLE", "ST. CHARLES", "ST. FRANCIS", "ST. JOE", "ST. PAUL", "SALEM", "SALEM", "SALESVILLE",
                                                                                                            "SCOTT", "SCRANTON", "SEARCY", "SEDGWICK", "SHANNON HILLS", "SHERIDAN", "SHERRILL", "SHERWOOD", "SHIRLEY", "SIDNEY", "SILOAM SPRINGS", "SMACKOVER", "SMITHVILLE",
                                                                                                            "SOUTH LEAD HILL", "SPARKMAN", "SPRINGDALE", "SPRINGTOWN", "STAMPS", "STAR CITY", "STEPHENS", "STRAWBERRY", "STRONG", "STUTTGART", "SUBIACO", "SUCCESS",
                                                                                                            "SULPHUR ROCK", "SULPHUR SPRINGS", "SUMMIT", "SUNSET", "SWEET HOME", "SWIFTON", "TAYLOR", "TEXARKANA", "THORNTON", "TILLAR", "TINSMAN", "TOLLETTE",
                                                                                                            "TONTITOWN", "TRASKWOOD", "TRUMANN", "TUCKERMAN", "TULL", "TUPELO", "TURRELL", "TWIN GROVES", "TYRONZA", "ULM", "VALLEY SPRINGS", "VAN BUREN", "VANDERVOORT",
                                                                                                            "VICTORIA", "VILONIA", "VIOLA", "WABBASEKA", "WALDENBURG", "WALDO", "WALDRON", "WALNUT RIDGE", "WARD", "WARREN", "WASHINGTON", "WATSON", "WEINER", "WELDON",
                                                                                                            "WEST CROSSETT", "WESTERN GROVE", "WEST FORK", "WEST HELENA", "WEST MEMPHIS", "WEST POINT", "WHEATLEY", "WHELEN SPRINGS", "WHITE HALL"
                                                                                                          ]
                                                                                                          }
                                                                                                        ]
                                                                                                      }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Apr-27 at 16:44

                                                                                                      You can do it with the $event parameter. Make sure to compare your values safely.

                                                                                                      If your value is not in the right type or has spaces or unwanted chars, this c.state == val might not work.

                                                                                                      You can use the trim function to compare your value safely: c.state.trim() == val.trim()

                                                                                                      HTML

                                                                                                      
                                                                                                      

                                                                                                      TS

                                                                                                      getCitiesForSelectedState(val:string){
                                                                                                        this.cities = StateCities?.city.find(c=> c.state.trim() == val.trim()).cities;
                                                                                                      }
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/67284495

                                                                                                      QUESTION

                                                                                                      RUBY: Rotate Function not Working on Array in Unit Test
                                                                                                      Asked 2021-Mar-12 at 04:16

                                                                                                      I am testing code output in Ruby. I want to use Ruby's rotate() function to make the last element of an array the first element, the original first element becomes the second element in the array, etc.

                                                                                                      CODE

                                                                                                      require 'minitest/autorun'
                                                                                                      class TestMagicBus < MiniTest::Test
                                                                                                      
                                                                                                        def setup
                                                                                                          @bus = MagicBus.new(["Peter","James","Bardoe","Patrick","Jake","Samson","Dave"])
                                                                                                        end
                                                                                                      
                                                                                                        def test_move_the_last_passenger_to_the_front_of_the_bus
                                                                                                          assert_equal "Peter", @bus[0]
                                                                                                          @bus.rotate(-1)
                                                                                                          print(@bus)
                                                                                                          assert_equal "Dave", @bus[0]
                                                                                                        end
                                                                                                      

                                                                                                      TEST RESULT

                                                                                                      ["Peter", "James", "Bardoe", "Patrick", "Jake", "Samson", "Dave"]F
                                                                                                      
                                                                                                      Failure:
                                                                                                      TestMagicBus#test_move_the_last_passenger_to_the_front_of_the_bus [magic_bus.rb:56]:
                                                                                                      Expected: "Dave"
                                                                                                        Actual: "Peter"
                                                                                                      
                                                                                                      
                                                                                                      rails test magic_bus.rb:52
                                                                                                      

                                                                                                      Why is rotate() not doing anything?

                                                                                                      DEFINITION of CLASS MAGICBUS

                                                                                                      class MagicBus < Array
                                                                                                      
                                                                                                        attr_writer :seating
                                                                                                      
                                                                                                      end
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Mar-12 at 04:16

                                                                                                      Most Ruby built-in methods that does not end with ! creates a copy of the operating object, so @bus.rotate create a new MagicBus object with the rotated result, and that's why @bus = @bus.rotate -1 works.

                                                                                                      To modify objects in-place, there's an Array#rotate! method:

                                                                                                      @bus.rotate! -1
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/66594025

                                                                                                      QUESTION

                                                                                                      Javascript Filter trying to avoid multiple if statements
                                                                                                      Asked 2021-Mar-03 at 17:29

                                                                                                      Hi I have to filter an array based on some conditions. I want to avoid having to write out a bunch if statements. My code below shows pretty much what I want to accomplish. The * you see is just me trying to say filter to any (like a wild card). Do you have any idea how I can best accomplish my goal? Thank you

                                                                                                      let x =eq.filter(eq => eq.empid == selectedTech === 'ALL Techs'? '*' : selectedTech 
                                                                                                          &&  eq.code == selectedStatus === 'ALL Statuses'? '*' : selectedStatus 
                                                                                                          &&  eq.cellnum == phn === '' ? '*': phn
                                                                                                          &&  eq.jobid == jobid === '' ? '*': jobid
                                                                                                          );
                                                                                                      

                                                                                                      Example of the object:

                                                                                                      var eq = [{
                                                                                                        empid: 1,
                                                                                                        jobid: 27,
                                                                                                        code: "Not Started",
                                                                                                        cellnum: "3058888888",
                                                                                                        brand: "GK",
                                                                                                        model: "X500"
                                                                                                      }, {
                                                                                                        empid: 1,
                                                                                                        jobid: 33,
                                                                                                        code: "Not Started",
                                                                                                        cellnum: "3058888899",
                                                                                                        brand: "Mackie",
                                                                                                        model: "X500"
                                                                                                      }, {
                                                                                                        empid: 2,
                                                                                                        jobid: 35,
                                                                                                        code: "In Progress",
                                                                                                        cellnum: "3058888877",
                                                                                                        brand: "Samson",
                                                                                                        model: "X522"
                                                                                                      }, {
                                                                                                        empid: 1,
                                                                                                        jobid: 36,
                                                                                                        code: "Not Started",
                                                                                                        cellnum: "3058888866",
                                                                                                        brand: "Mackie",
                                                                                                        model: "X467"
                                                                                                      }, {
                                                                                                        empid: 1,
                                                                                                        jobid: 37,
                                                                                                        code: "In Progress",
                                                                                                        cellnum: "3058888800",
                                                                                                        brand: "Fender",
                                                                                                        model: "X500"
                                                                                                      }]
                                                                                                      }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Mar-03 at 17:29

                                                                                                      You don't need '*', use eq.whatever there since it will be guaranteed to compare equal to itself.

                                                                                                      And use parentheses to ensure that the precedence is what you want. I'm not sure offhand how the == precedence compares to the tertiary.

                                                                                                      let x = eq.filter(eq => eq.empid == (selectedTech === 'ALL Techs' ? eq.empid : selectedTech) &&
                                                                                                        eq.code == (selectedStatus === 'ALL Statuses' ? eq.code : selectedStatus) &&
                                                                                                        eq.cellnum == (phn === '' ? eq.cellnum : phn) &&
                                                                                                        eq.jobid == (jobid === '' ? eq.jobid : jobid)
                                                                                                      );

                                                                                                      Maybe a clearer way to do it is either compare the filter variable to its wildcard value or the object property.

                                                                                                      var eq = [{
                                                                                                        empid: 1,
                                                                                                        jobid: 27,
                                                                                                        code: "Not Started",
                                                                                                        cellnum: "3058888888",
                                                                                                        brand: "GK",
                                                                                                        model: "X500"
                                                                                                      }, {
                                                                                                        empid: 1,
                                                                                                        jobid: 33,
                                                                                                        code: "Not Started",
                                                                                                        cellnum: "3058888899",
                                                                                                        brand: "Mackie",
                                                                                                        model: "X500"
                                                                                                      }, {
                                                                                                        empid: 2,
                                                                                                        jobid: 35,
                                                                                                        code: "In Progress",
                                                                                                        cellnum: "3058888877",
                                                                                                        brand: "Samson",
                                                                                                        model: "X522"
                                                                                                      }, {
                                                                                                        empid: 1,
                                                                                                        jobid: 36,
                                                                                                        code: "Not Started",
                                                                                                        cellnum: "3058888866",
                                                                                                        brand: "Mackie",
                                                                                                        model: "X467"
                                                                                                      }, {
                                                                                                        empid: 1,
                                                                                                        jobid: 37,
                                                                                                        code: "In Progress",
                                                                                                        cellnum: "3058888800",
                                                                                                        brand: "Fender",
                                                                                                        model: "X500"
                                                                                                      }];
                                                                                                      
                                                                                                      let selectedTech = 'ALL Techs',
                                                                                                        selectedStatus = 'In Progress',
                                                                                                        phn = '3058888800',
                                                                                                        jobid = 37;
                                                                                                      
                                                                                                      let x = eq.filter(eq =>
                                                                                                        (selectedTech === 'ALL Techs' || eq.empid == selectedTech) &&
                                                                                                        (selectedStatus === 'ALL Statuses' || eq.code == selectedStatus) &&
                                                                                                        (phn === '' || eq.cellnum == phn) &&
                                                                                                        (jobid === '' || eq.jobid == jobid)
                                                                                                      );
                                                                                                      
                                                                                                      console.log(x);
                                                                                                      
                                                                                                      phn = "123456789";
                                                                                                      
                                                                                                      x = eq.filter(eq =>
                                                                                                        (selectedTech === 'ALL Techs' || eq.empid == selectedTech) &&
                                                                                                        (selectedStatus === 'ALL Statuses' || eq.code == selectedStatus) &&
                                                                                                        (phn === '' || eq.cellnum == phn) &&
                                                                                                        (jobid === '' || eq.jobid == jobid)
                                                                                                      );
                                                                                                      
                                                                                                      console.log(x);

                                                                                                      Source https://stackoverflow.com/questions/66447869

                                                                                                      QUESTION

                                                                                                      Toggle Accordion functionality with reactstrap?
                                                                                                      Asked 2021-Feb-21 at 04:30

                                                                                                      Using the reactstrap documentation, I created a pseudo-accordion with collapsible cards. I want to be able to toggle the cards, so that when I click on the card header of list 2 once it will open, and it will close again if I click it consecutively. If I click list 1, list 2 should close and list 1 should open, as expected.

                                                                                                      Accordion Component:

                                                                                                      import React, { Fragment, useState } from 'react';
                                                                                                      import { Collapse, CardBody, Card, CardHeader } from 'reactstrap';
                                                                                                      
                                                                                                      const Lists = () => {
                                                                                                          const [isOpen, setIsOpen] = useState('');
                                                                                                          const [lists, setLists] = useState([
                                                                                                              {
                                                                                                                  _id: 'id_abc',
                                                                                                                  item_names: ['item 1', 'item 2', 'item 3'],
                                                                                                                  list_name: 'List 2',
                                                                                                                  author_name: 'Samantha Samson',
                                                                                                              },
                                                                                                              {
                                                                                                                  _id: 'id_xyz',
                                                                                                                  item_names: ['item 1', 'item 1', 'item 2', 'item 16'],
                                                                                                                  list_name: 'List 1',
                                                                                                                  author_name: 'John Johnson',
                                                                                                              },
                                                                                                          ]);
                                                                                                      
                                                                                                      return (
                                                                                                          
                                                                                                              {lists.map((list) => (
                                                                                                                  
                                                                                                                       setIsOpen(list._id)}>
                                                                                                                          {list.list_name}
                                                                                                                      
                                                                                                                      
                                                                                                                          
                                                                                                                              
                                                                                                        
                                                                                                        {list.item_names.map((item) => (
                                                                                                      • {item}
                                                                                                      • ))}
                                                                                                      ))} );

                                                                                                      I tried adding a function to the onClick that looked like this:

                                                                                                      const handleToggle = (id) => {
                                                                                                          if(isOpen === id) {
                                                                                                              setIsOpen('');
                                                                                                          } else {
                                                                                                              setIsOpen(id);
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      and gave the header:

                                                                                                      onClick={handleToggle(list._id)}
                                                                                                      

                                                                                                      but that gave many a too many rerenders/infinite loop error.

                                                                                                      I also tried slight variations of that function with the same result.

                                                                                                      ANSWER

                                                                                                      Answered 2021-Feb-21 at 04:30

                                                                                                      You have pretty much fixed it with this one:

                                                                                                        const handleToggle = (id) => {
                                                                                                          if (isOpen === id) {
                                                                                                            setIsOpen("");
                                                                                                          } else {
                                                                                                            setIsOpen(id);
                                                                                                          }
                                                                                                        };
                                                                                                      

                                                                                                      So great job! Where you made a mistake is calling it like so:

                                                                                                      onClick={handleToggle(list._id)}
                                                                                                      

                                                                                                      This will call the function on every render and since it updates a state variable, you will get infinite renders.

                                                                                                      It should be:

                                                                                                      onClick={() => handleToggle(list._id)}
                                                                                                      

                                                                                                      Sandbox: https://codesandbox.io/s/hungry-jepsen-1ip0x?file=/src/App.js

                                                                                                      Just FYI: You can simplify your ternary operator as:

                                                                                                      isOpen={isOpen === list._id}
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/66299089

                                                                                                      QUESTION

                                                                                                      group result using date from object keys and only get count the results
                                                                                                      Asked 2021-Jan-29 at 03:55

                                                                                                      Hello I'm having a hard time getting this complex return using MongoDB nor Javascript. Hope can anyone teach me how to get this return.

                                                                                                      Admin.

                                                                                                      group result by id

                                                                                                      user flatten result

                                                                                                      Here's the data example.

                                                                                                      let user = [
                                                                                                          {
                                                                                                        _id: 123,
                                                                                                        name: 'John',
                                                                                                        createdAt: "2015-08-12T00:00:00Z"
                                                                                                        },
                                                                                                        {
                                                                                                        _id: 124,
                                                                                                        name: 'Jane',
                                                                                                        createdAt: "2015-09-12T00:00:00Z"
                                                                                                        },
                                                                                                        {
                                                                                                        _id: 125,
                                                                                                        name: 'Robert',
                                                                                                        createdAt: "2015-09-12T00:00:00Z"
                                                                                                        },
                                                                                                        {
                                                                                                        _id: 126,
                                                                                                        name: 'Samson',
                                                                                                        createdAt: "2016-11-12T00:00:00Z"
                                                                                                        }
                                                                                                      ]
                                                                                                      

                                                                                                      Expected Result

                                                                                                      user

                                                                                                      [
                                                                                                      {
                                                                                                       "15-8": 1 //yyyy-mm: number of data for the month of august
                                                                                                      },
                                                                                                      {
                                                                                                       "15-9": 2
                                                                                                      },
                                                                                                      {
                                                                                                       "16-11": 1
                                                                                                      }
                                                                                                      ]
                                                                                                      

                                                                                                      admin

                                                                                                      [
                                                                                                          {
                                                                                                           "15-8": 
                                                                                                         {
                                                                                                          _id: 123,
                                                                                                          count: 1
                                                                                                         }
                                                                                                          },
                                                                                                          {
                                                                                                           "15-9": {
                                                                                                           _id: 124,
                                                                                                           count: 1,
                                                                                                         },{
                                                                                                           _id: 125,
                                                                                                           count: 1
                                                                                                          },
                                                                                                          {
                                                                                                           "16-11": {
                                                                                                           _id: 126,
                                                                                                           count: 1
                                                                                                           }
                                                                                                          }
                                                                                                          ]
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Jan-29 at 03:46
                                                                                                      1. You should have the function to get key from date string named getKeyFromDate with format result YY-MM

                                                                                                      2. Loop user data to aggregate your data by using reduce, for example.

                                                                                                      let user = [
                                                                                                          {
                                                                                                            _id: 123,
                                                                                                            name: 'John',
                                                                                                            createdAt: "2015-08-12T00:00:00Z"
                                                                                                          },
                                                                                                          {
                                                                                                            _id: 124,
                                                                                                            name: 'Jane',
                                                                                                            createdAt: "2015-09-12T00:00:00Z"
                                                                                                          },
                                                                                                          {
                                                                                                            _id: 125,
                                                                                                            name: 'Robert',
                                                                                                            createdAt: "2015-09-12T00:00:00Z"
                                                                                                          },
                                                                                                          {
                                                                                                            _id: 126,
                                                                                                            name: 'Samson',
                                                                                                            createdAt: "2016-11-12T00:00:00Z"
                                                                                                          }
                                                                                                      ];
                                                                                                      
                                                                                                      const getKeyFromDate = (dateString) => {
                                                                                                        var date = new Date(dateString);
                                                                                                        var year = date.getFullYear().toString().substr(2, 3);
                                                                                                        var month = date.getMonth() + 1;
                                                                                                        return `${year}-${month}`; // YY-MM
                                                                                                      };
                                                                                                      
                                                                                                      var result = user.reduce((acc, {createdAt}) => {
                                                                                                        var key = getKeyFromDate(createdAt);
                                                                                                        acc[key] = acc[key] || {[key]: 0}; //Also use shortcut like: acc[key] ??= {[key]: 0};
                                                                                                        acc[key][key] += 1;
                                                                                                        return acc; 
                                                                                                        
                                                                                                      }, {});
                                                                                                      console.log(Object.values(result));

                                                                                                      You can also use for..of if you're not familiar with .reduce

                                                                                                      var result2 = {};
                                                                                                      for(let {createdAt} of user){
                                                                                                        var key = getKeyFromDate(createdAt);
                                                                                                        result2[key] = result2[key] || {[key]: 0};
                                                                                                        result2[key][key] += 1;
                                                                                                      }
                                                                                                      console.log(Object.values(result2));
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/65947873

                                                                                                      QUESTION

                                                                                                      Get name HttpClient from IHttpClientFactory injected with DI
                                                                                                      Asked 2020-Dec-02 at 14:02

                                                                                                      In Blazor I have setup two HttpClients. One for my API and one for MS Graph API. The Graph API is new, and have forced me to find a way to inject a named httpclient in to my services.

                                                                                                      This is all the code in Main

                                                                                                        public class Program
                                                                                                      {
                                                                                                          public static async Task Main(string[] args)
                                                                                                          {
                                                                                                              var b = WebAssemblyHostBuilder.CreateDefault(args);
                                                                                                              b.RootComponents.Add("app");
                                                                                                      
                                                                                                              var samsonApiUrl = new Uri(b.HostEnvironment.BaseAddress + "api/");
                                                                                                      
                                                                                                              b.Services.AddHttpClient("SamsonApi",client => 
                                                                                                              {
                                                                                                                 client.BaseAddress = samsonApiUrl;
                                                                                                                 // add jwt token to header
                                                                                                                 // add user agent to header
                                                                                                              }).AddHttpMessageHandler();
                                                                                                              
                                                                                                              b.Services.AddTransient();
                                                                                                              b.Services.AddHttpClient("GraphAPI",
                                                                                                                      client => client.BaseAddress = new Uri("https://graph.microsoft.com/"))
                                                                                                                  .AddHttpMessageHandler();
                                                                                                              
                                                                                                              b.Services.AddScoped(provider => provider.GetService().CreateClient("SamsonApi"));
                                                                                                              b.Services.AddScoped(provider => provider.GetService().CreateClient("GraphAPI"));
                                                                                                              
                                                                                                              b.Services.AddMsalAuthentication(options =>
                                                                                                              {
                                                                                                                  b.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication);
                                                                                                                  options.ProviderOptions.DefaultAccessTokenScopes.Add("1c8d4e31-97dd-4a54-8c2b-0d81e4356bf9/API.Access");
                                                                                                                  options.UserOptions.RoleClaim = "role";
                                                                                                              }).AddAccountClaimsPrincipalFactory();
                                                                                                              
                                                                                                              
                                                                                                              // add Radzen services 
                                                                                                              b.Services.AddScoped();
                                                                                                              b.Services.AddScoped();
                                                                                                              b.Services.AddScoped();
                                                                                                              // add samson component services
                                                                                                              b.Services.AddSingleton();
                                                                                                              // Add Http Services
                                                                                                              b.Services.Scan(scan =>
                                                                                                                  {
                                                                                                                      scan.FromAssemblyOf()
                                                                                                                          .AddClasses(classes => classes.Where(type => type.Name.EndsWith("Service")))
                                                                                                                          .AsMatchingInterface()
                                                                                                                          .WithScopedLifetime();
                                                                                                                  });
                                                                                                              await b.Build().RunAsync();
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      This is the code that has to change. It's scan all my service and get a HttpClient injected. And since I now have two I get a random client injected. How can I inject a named client into all of my services? I can handle the graph API service as a special case.

                                                                                                       b.Services.Scan(scan =>
                                                                                                                  {
                                                                                                                      scan.FromAssemblyOf()
                                                                                                                          .AddClasses(classes => classes.Where(type => type.Name.EndsWith("Service")))
                                                                                                                          .AsMatchingInterface()
                                                                                                                          .WithScopedLifetime();
                                                                                                                  });
                                                                                                      

                                                                                                      Example of a service calling my API

                                                                                                       public class ActiveAgreementService : IActiveAgreementService
                                                                                                      {
                                                                                                          private readonly HttpClient _client;
                                                                                                          
                                                                                                          public ActiveAgreementService(HttpClient client)
                                                                                                          {
                                                                                                              _client = client;
                                                                                                          }
                                                                                                      
                                                                                                          public async Task> GetActiveAgreements()
                                                                                                          {
                                                                                                              var lst = await _client.GetFromJsonAsync("ActiveAgreement");
                                                                                                              return lst.ToList();
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      Okay ended up with replacing HttpClient with IHttpClientFactory in all my services

                                                                                                      public UserService(IHttpClientFactory clientFactory)
                                                                                                      {
                                                                                                         _client = clientFactory.CreateClient("SamsonApi");
                                                                                                      }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2020-Dec-01 at 17:16

                                                                                                      I assume you're using ASP.NET Core, although it's not clear which dependency injection framework you're using.

                                                                                                      In that case, you could have your classes depend on IHttpClientFactory and then setup the configuration with named clients:

                                                                                                      // Named client like you're currently doing
                                                                                                      b.Services.AddHttpClient("SamsonApi", client => 
                                                                                                      {
                                                                                                          client.BaseAddress = samsonApiUrl;
                                                                                                          // add jwt token to header
                                                                                                          // add user agent to header
                                                                                                      }).AddHttpMessageHandler();
                                                                                                      
                                                                                                      //...
                                                                                                      
                                                                                                      b.Services.AddHttpClient("GraphAPI", client =>
                                                                                                          client.BaseAddress = new Uri("https://graph.microsoft.com/"))
                                                                                                          .AddHttpMessageHandler();
                                                                                                      
                                                                                                      // And in your dependent class
                                                                                                      public class ActiveAgreementService : IActiveAgreementService
                                                                                                      {
                                                                                                          private readonly HttpClient _client;
                                                                                                          
                                                                                                          public ActiveAgreementService(IHttpClientFactory clientFac)
                                                                                                          {
                                                                                                              // Whichever one you need:
                                                                                                              _client = clientFac.CreateClient("SamsonApi");
                                                                                                              _client = clientFac.CreateClient("GraphAPI");
                                                                                                          }
                                                                                                      
                                                                                                          public async Task> GetActiveAgreements()
                                                                                                          {
                                                                                                              var lst = await _client.GetFromJsonAsync("ActiveAgreement");
                                                                                                              return lst.ToList();
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      ... or with typed clients you specify the instance for each class that depends on it:

                                                                                                      // This HttpClient is only injected into ActiveAgreementService
                                                                                                      b.Services.AddHttpClient(client => 
                                                                                                      {
                                                                                                          client.BaseAddress = samsonApiUrl;
                                                                                                          // add jwt token to header
                                                                                                          // add user agent to header
                                                                                                      }).AddHttpMessageHandler();
                                                                                                      
                                                                                                      //...
                                                                                                      
                                                                                                      // This HttpClient is only injected into GraphHttpClientService
                                                                                                      b.Services.AddHttpClient(client =>
                                                                                                          client.BaseAddress = new Uri("https://graph.microsoft.com/"))
                                                                                                          .AddHttpMessageHandler();
                                                                                                      
                                                                                                      // And in your dependent class
                                                                                                      public class ActiveAgreementService : IActiveAgreementService
                                                                                                      {
                                                                                                          private readonly HttpClient _client;
                                                                                                          
                                                                                                          public ActiveAgreementService(HttpClient client)
                                                                                                          {
                                                                                                              _client = client;
                                                                                                          }
                                                                                                      
                                                                                                          public async Task> GetActiveAgreements()
                                                                                                          {
                                                                                                              var lst = await _client.GetFromJsonAsync("ActiveAgreement");
                                                                                                              return lst.ToList();
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/65094747

                                                                                                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                                      Vulnerabilities

                                                                                                      No vulnerabilities reported

                                                                                                      Install samson

                                                                                                      You can download it from GitHub.
                                                                                                      On a UNIX-like operating system, using your system’s package manager is easiest. However, the packaged Ruby version may not be the newest one. There is also an installer for Windows. Managers help you to switch between multiple Ruby versions on your system. Installers can be used to install a specific or multiple Ruby versions. Please refer ruby-lang.org for more information.

                                                                                                      Support

                                                                                                      Getting startedBasic ComponentsPermissionsContinuous IntegrationExtra featuresPluginsStatisticsAPI
                                                                                                      Find more information at:
                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit
                                                                                                      CLONE
                                                                                                    • HTTPS

                                                                                                      https://github.com/zendesk/samson.git

                                                                                                    • CLI

                                                                                                      gh repo clone zendesk/samson

                                                                                                    • sshUrl

                                                                                                      git@github.com:zendesk/samson.git

                                                                                                    • Share this Page

                                                                                                      share link

                                                                                                      Explore Related Topics

                                                                                                      Reuse Pre-built Kits with samson

                                                                                                      Consider Popular Continuous Deployment Libraries

                                                                                                      Try Top Libraries by zendesk

                                                                                                      maxwell

                                                                                                      by zendeskJava

                                                                                                      cross-storage

                                                                                                      by zendeskJavaScript

                                                                                                      ruby-kafka

                                                                                                      by zendeskRuby

                                                                                                      helm-secrets

                                                                                                      by zendeskShell

                                                                                                      Compare Continuous Deployment Libraries with Highest Support

                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit