7-Tips for Starting a React Project!
When to use classes and functional components in React!
When I started coding in React I would always wonder why everything didn’t just use a class component when coding, it would make life a lot easier to follow I use to think. But, I learned that they have advantages of using each type when needed. React’s project architect is…
Python-algos: Sentence Reversal
Given a string of words, reverse all the words. For example: “Hi my name is Avi”, becomes “Avi is name my Hi”. def rev_word3(s): words =  length = len(s) spaces = [' '] i = 0 while i < length: if s[i] not in spaces: word_start = i while i < length and s[i] not in spaces: i += 1 words.append(s[word_start:i]) i += 1 return " ".join(reversed(words))
Python-algos: Largest Continuous Sum
Given an array of integers (positive and negative) find the largest continuous sum. An example of an array would be the following: [7,2,-6,3,4,10,10,-10,-10] . The array’s maximum sum would be 30, summing everything until the last two -10’s are not included in the sum. def large_cont_sum(arr): if len(arr)==0: return 0 max_sum = current_sum = arr for num in arr[1:]: current_sum = max(current_sum + num, num) max_sum = max(current_sum, max_sum) return max_sum
Python-Algos: Find the Missing Element
Consider an array of non-negative integers. A second array is formed by shuffling the elements of the first array and deleting a random element. Given the two arrays, find which element is missing in the second array. def findt_missing(arr1,arr2): arr1.sort() arr2.sort() for num1, num2 in zip(arr1,arr2): if num1 != num2: return num1 return arry1[-1] The zip() function returns a zip object, which is an iterator of tuples where the first item in each passed iterator is paired together, and then the second item in each passed iterator are paired together etc.
Python-Algos: Array Pair Sum
They’re many ways to approach this problem, but you have to consider the time it takes to run the code once the data becomes much bigger than your sample test data. The Array Pair Sum problem: Given an integer array, output all the unique pairs that sum up to a specific value C. def pair_sum(arr, C): if len(arr)<2: return seen = set() output = set() for num in arr: target = C - num if target not in seen: seen.add(num) else: output.add((min(num,target), max(num,target))) print ('\n'.join(map(str,list(output))))
What is a Rails API?
Application programming interface or API, is a software intermediary that allows for two applications to talk to each other. In other words, an API is the messenger that delivers your request and responses from the front end to the back end of your program (client side rendering). API’s are designed…
Ruby on Rails: Authorization
Devise gem is a beautiful gem. Inside your gemfile, require: gem 'devise', '~> 4.7', '>= 4.7.1' Or which ever version is the most updated. Run bundle install to grab the library and any dependencies for your rails project.Next, you need to run the generator: rails generate devise:install Open the devise.rb…