Stubs, mocks, spies and fakes

Definitions
Stub
Minimal implementations of interfaces or base classes
Spy
A Spy will record which members were invoked
Fake
More complex, a fake may resemble a production implementation
Mock
It is usually dynamically created by a mock library and depending in its configuration a mock can behave like a dummy, a stub, or a spy.
Comments
All
They all relate to functions, objects and other types.
Stub
Stubbing is a way to provide dummy data/info instead of making the calling to the actual DB
Fake
It is for example a function which you create inside the test file to mimic the real function or be a simplified version of the actual function.

Thank you post to Flatiron

I’ve completed the self-paced Online Software Engineering bootcamp with Flatiron School and through that year I was able to gain a “tech family” and grow as a developer.

My background is in the art market and it was not easy for me to get into the dev world. I was a new mum and had to take care of my daughter too. My time was limited and I got quite often long periods of baby sickness, lots of until late study nights and “I am not going to get this” tears but I finally graduated! Flatiron School was helping me through my journey with their technical help, ask a question feature and lessons.

I started to look for a job in January and 5 weeks laterĀ I’ve accepted an amazing job offer. During those weeks I was doing tons of code challenges, lots of interviews and getting rejections almost every week. But I had Emma helping me! She was my career coach. She was helping me with my emotions, with my interview skills, and giving me good advice. THANK YOU Emma!

I am not sure that this blog post is going to comply with Flatiron requirements of a one technical blog post but I can treat it as an algorithm to become a developer:

  1. Make sure your passion is coding.
  2. Enroll at Flatiron.
  3. Study, be curious, share your knowledge, have fun with side projects too.
  4. Graduate.
  5. Land your dream job as a dev and start an amazing new career!

Virtual environment (Python)

Create a virtual environment for your Python app in a few steps. (For Linux and OS X). Go inside the directory where you want your virtual environment and type in the terminal:

This command will create a directory called myvenv with the virtual environment.

Start your virtual environment by running:

Now that you inside the virtual environment (you will know it because the prompt of the console is prefixed with ( myenv )) you can install whatever you need using pip. To get the latest version of pip type:

When working within a virtual environment, python will automatically refer to the correct version so you don’t need to specify anything.

Create a requirements.text file and add packages inside.

Run the following to install them:

The end! Happy coding!

Junior developer interview questions

I am looking for my first job as a Junior developer and during my interviews I was asked the following:

  • Difference between === and ==:
    • === Compares the value ad the type (true / false).
    • == Compares only type.
  • Difference between slack and heap memories:
    • Slack memory: local variables and function call.
    • Heap memory: store objects.
  • Difference between data type and data structure:
    • Data type: the most basic classification. (int, string, var).
    • Data structure: collection of data types. (stacks (LIFO(last in first out)), queues, linked lists, binary tree)
  • Difference between padding and margin:
    • paddingĀ is the space between the content and theĀ border, whereasĀ marginĀ is the space outside the border.

Time complexity

  • You can get it counting the number of operations
  • Time complexity is defined as a function using Big O notation.
  • n is the size of the input.
  • O is the worst case scenario.
  • The O function is the growth rate in function of the input size n.

O(1) Constant : odd or even / look up table / check if item in array is null / print first element from a list / find on a map.

O(log n) Logarithmic: find in sorted array with binary search.

O(n) Linear: find max in unsorted array / duplicate elements in array with Hash map / find / print all values.

Algorithms running times:

Factorial complexity(no good),

exponential complexity(no good),

polinomial complexity (no good),

linearithmic complexity (middle point),

linear time complexity (good)(for loop in one level array, searching, printing) O(n),

logarithmic complexity (good) O(log n),

constant time complexity (best one)(swap variables). O(1)

Time Conversion

Problem from Hackerranck.

I am practising algorithms and tried this one today.

I first get the two first characters of the string ‘s’, the ones that represent the hour and change them to a number with parseInt and assign them to the variable hour.

If this variable hour is bigger than 12 I rest 12, if it is equals 12, hour would be the string ’00’ and for the rest of the cases I add 12.

Then I add hour to a substring of the argument without the two first characters and delete the two last characters too, the one that should be “AM” or “PM”.

My solution:

SuperGenPy

Creating a Django app with a Postgres db using Docker Compose.

I was following this greatĀ tutorial.

To run the app:

docker-composeĀ upĀ commandĀ fromĀ theĀ topĀ levelĀ directoryĀ forĀ yourĀ project.

TheĀ appĀ shouldĀ beĀ runningĀ atĀ portĀ 8000Ā onĀ yourĀ DockerĀ host.

Now that I have my app set and running I want to start creating my content.

I want to create an app where users can login/logout securely and perform CRUD operations with their logins.Ā  That means I will need a Login model. Each login will have some attributes too: a version, length, hash, type and prefix.

Some webs ask you to change your password many times so you can store in this interface the number of the version where you are currently, and don’t have to remember it. Same thing happens with that extras that some webs ask you, like a specific length, or special characters that the SuperGenPass don’t use. If a web asks me about a special character I put it at the beginning of the generated password. This interface would be a great place where you can store all info without compromising your security.

Creating my model.

To be tidy, I am going to create a new app, dashboard, and let know to Django to use it, in supergenpy/settings.py I add ‘dashboard’ to INSTALLED_APPS.

I create my Login model inside models.py and run my migrations:

docker-compose run web python manage.py migrate --noinput

Now, what I want is to see my Login model! For that I create a superuser.

I need the id of my docker-compose container:

docker-compose ps -q

and I run the following command

docker exec -it container_id python manage.py createsuperuser

When you run this command, the server has to be running.

Then, you can return to the browser and login in the admin dashboard (http://localhost:8000/admin/) with the credentials you have set up in the command line when creating the superuser.

After graduating

After a good break with family I am back in London to start looking for a job. Only one hour after I have opened my laptop I got a LinkedIn message from a fintech startup offering an opportunity for a developer. Half an hour later I had a phone call with them! Incredible!

The are looking for a developer working with javascript, node, react native and other softwares. I don’t have any experience with react native but asked them for a week, so I could study and try their code challenge!

Nervous!! But I got the following course. Let’s dive deep into it!

For what I have understood React Native is a fast framework where you can use your knowledge of React.js and JavaScript.

I doesn’t allow you to use HTML tags, it has its own special components compiled to native views:

<div> would be <View>

<input> would be <TextInput>

The logic of the app is not compiled. JS is thread hosted by React Native app. It runs inside a virtual machine inside your native app, the Javascript core, and you still have access to the native platform, the modules and the API. So you create your app with JS and these special components.

Creating a new native app.

There are two different ways:

-expo-cli tool, Expo is a third party service and it gives you a managed app development.Is simplifies the development but it has limits!

-and react native CLI. It is managed by the react team. Bare-bone development.

Expo is easier to use and if any case you need more flexibility you can “eject” and switch to the react native CLI.

Using Expo what you do is install an app, the Expo client, to your native device or simulator that is your phone, laptop… and so your app(all your code and configuration) can be loaded into the Expo App. Expo allows you to publish standalone apps too.

Complexity Theory cheat sheet

Space complexity: how much memory an algorithm needs

Time complexity: how much time an algorithm needs

We do care about time complexity, but how do we measure absolute time?

With the number of steps.

The algorithm’s running time depends on the number of items of the input, the input size.

The order of growth: how the algorithm will scale and behave with the input size.

For us it is very important the connexion between the running time and the input size.

Linear time complexity

Our goal is ended up with an approximately linear algorithm in terms of the input. If the algorithm needs 1 ms to process 10 items, 2 ms for 20 items and 10 ms for 100 items it is a linear algorithm. If the third step take for example 100 ms it wouldn’t be linear.

Asymptotic analysis

We only care about the big size inputs and we only keep the terms that grow fast as N becomes larger.

Complexity notations:

  1. The big ordo notation (o)

Describes the running time in terms of the input size.

f(n) = O( g(n) )

f is the running time

n is the input size

2. Big omega notation

It describes the limiting behaviour of a function.

f(n) =Ā Ī©( g(n) )

3. Big theta notation

It describes the limiting behaviour of a function.

f(n) =Ā Ī˜( g(n) )

Algorithms running times:

Factorial complexity(no good),

exponential complexity(no good),

polinomial complexity (no good),

linearithmic complexity (middle point),

linear time complexity (good)(for loop in one level array, searching, printing) O(N),

logarithmic complexity (good),

constant time complexity (best one)(swap variables). O(1)

Complexity classes:

P (polynomial),

NP (nondeterministic polynomial),

NP-complete (the hardest problems in NP),

NP-hard

Linear search

We have a one dimension array and want to search for a number.

Best case scenario: the first time item is the one we are looking for. O(1) running time.

Worst case scenario: the item is not in the array. O(N) running time.

Average case scenario: Item is uniformly distributed from the first index to the last index. O(N) running time.

Binary search

We want to find an item in an array, this time the array is sorted. We can use binary search only if the array is sorted.

If we know de index we can get it with O(1) constant time complexity.

If we don’t know the index we can start at the middle, on every iteration we can discard half the items.

Binary search has logarithmic running time. O(logN)

Bubble sort

Repeatedely steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order.

It is too slows and impractical.

Has quadratic running time O(N2).