nativo interview Flashcards

1
Q

git: to make git ignore certain files

A

before you commit, create a .gitignore file and add them into it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

git: A good commit message

A

is written as a command. “Remove the cruft”

and the body is, what, why and how.

“Add user accounts to allow user logins by integrating django allauth”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Python: To stop a for loop, use the command

A

break

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Python: To test if a number is even, type

A

number % 2 == 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Python: To switch the keys and values of a dictionary to be the values and keys using a dict comprehension, type

A

{value: key for key, value in my_dict.items()}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Python: __init__ is a

A

method that runs right when a class is instantiated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Python: An alternative to putting all of the parameters and defaults in a class’s def __init__(self, my_attribute=1, my_attribute2=2): you can just type

A
class Myclass:
    def \_\_init\_\_(self, **args):
        self.my_attribute = args.get("Name", "Bill")
        self.my_attribute2 = args.get("Age", 20)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Python: Every method in a class must at least take the

A

self argument. def my_method(self):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Python: The (self) argument represents

A

the data from the instance you are calling the method on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Python: Using self. in a class method allows you to

A

access the attributes of the instance you are calling the method on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Python: This function will return
def f():
    return

f()

A

None

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Python and Javascript imports start with

A
Python = from 
Javascript =  import

PFJI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Python: To create a class that takes two arguments upon instantiation, and has a method, type

A
class Myclass:
    def \_\_init\_\_(self, arg_1="default1", arg_2="default2"):
        self.arg_1 = arg_1
        self.arg_2 = arg_2
    def my_method(self):
        return self.arg_one*2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Python: To return a random list item, type

A

import random

random.choice(my_list)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Python: To capture any parameters that are passed into a class when being instantiated, but were not defined inside the class beforehand, type

A
class Myclass:
    def \_\_init\_\_(self, **args)
        self.my_attribute = args.get("arg", "default")
        for key, value in args.items():
            setattr(self, key, value)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

JS: “use strict” is

A

a string you can add to the top of a file or function in order to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

CS: The difference between an error and an exception is

A

An Error indicates a serious problem you should not try to catch. An Exception indicates a problem you might want to catch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Python: A decorator is just

A

syntactic sugar for creating a closure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Python: The three ways to wrap a closure around a function and call it are

def add(a, b):
    return a + b
A
@closure_function_name
def add(a, b):
    return a + b

add(1, 1)

or

add = closure_function_name(add)
add(1,1)

or

closure_function_name(add)(1, 1)

https: //www.youtube.com/watch?v=swU3c34d2NQ
https: //www.youtube.com/watch?v=MYAEv3JoenI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Python: Using a closure wrapper gives you an opportunity to

A

perform some operations before calling the original function (like logging) or altering the passed in parameters before passing them into original function or making the calling of the original function conditional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Python: A generator is

A

an object you can iterate on without loading the entire list into memory.

22
Q

Python: To create a generator, type

A

the steps are: make the generator function, then call it with your list.

def generator_function(iterable):
    for item in iterable:
        yield item * item

generator = generator_function([1,2,3])

or a generator comprehension

generator = (item * item for item in [1,2,3])

23
Q

Python: In functions, the yield keyword

A

sends the value passed to yield to the caller and pauses the function, but retains enough state so that it can resume when you call next(generator())
e.g.

def simpleGenerator(): 
    yield 1
    yield 2
    yield 3

for value in simpleGenerator():
print(value)

1
2
3

24
Q

Python: To get the results of a generator, type

A

next(generator)

or

for item in generator:

25
Q

Python: A closure is basically

A

closure_function(passed_in_function)(param1, param2)

a closure function gets called
puts the passed in function into the closure_function scope
can define some variables
defines an inside function which will maintain access to the closure_functions scope
the closure function returns a pointer to the inside function
the inside function gets called with parameters (must match number of params)
can do side effects, alter the parameters and call the passed_in_function with the parameters it was given

The closure_functions variables can be changed by using nonlocal variable_name

you create a function that takes a passed in function as a parameter, it has an inside function, and returns a pointer to the inside function. The inside function receives the parameters that you send into the closure when you call it and then you can manipulate the parameters or cause side effects or conditionally call the passed in function with new params

26
Q

Python: the order of where python looks for variable definitions is

A

LEGB

Local, Enclosing, Global, Built-in

27
Q

Python: To be able to change the value of a variable defined outside a function from inside a function, type

A

x = 10

def my_function():
    global x  #if it is defined the module level scope
    x = 20

or

def my_function():
    nonlocal x  #if it is defined in another function this function is nested it
    x = 20

https://www.youtube.com/watch?v=QVdf0LgmICw

28
Q

Python: A lambda function is

A

an anonymous function usually used for inline functions

29
Q

In python and JS everything is

A

an object

30
Q

JS: To have multiple callback functions type

A
function printList(callback) {
  // do your printList work
  console.log('printList is done');
  callback();
}
function updateDB(callback) {
  // do your updateDB work
  console.log('updateDB is done');
  callback()
}
function getDistanceWithLatLong(callback) {
  // do your getDistanceWithLatLong work
  console.log('getDistanceWithLatLong is done');
  callback();
}
function runSearchInOrder(callback) {
    getDistanceWithLatLong(function() {
        updateDB(function() {
            printList(callback);
        });
    });
}

runSearchInOrder(function(){console.log(‘finished’)});

The output will be:
getDistanceWithLatLong is done
updateDB is done
printList is done
finished
31
Q

JS: To make a function that takes a callback function, type

A

function funcName(callback) {
console.log(‘hi’)
callback()
}

funcName(function() {
console.log(‘there’)
})

or with arrows

let funcName = (callback) => {
console.log(‘hi’)
callback()
}

funcName(()=>{
console.log(‘there’)
})

the callback function passed into the calling function usually runs last

32
Q

JS: How a promise works is,

A

it runs the initial script inside the Promise declaration
new Promise(function(resolve, reject) {
setTimeout(() => resolve(1), 1000); // (*)
}).then(…)
and waits for resolve to be called inside the promise
After resolve is called .then() runs the function you passed in and uses the prior resolve value as the parameters
this .then function returns a promise and it uses the return value of your passed in function as the resolve value
it runs the next .then() or your function can return another promise and it will use the resolve value of that promise to pass into the next .then() function.

https://javascript.info/promise-chaining

33
Q

JS: if you do this, the .then functions will run

let myPromise = new Promise(function(resolve, reject) {
  setTimeout(() => resolve(1), 1000);
});

myPromise.then(function(result) {
alert(result); // 1
return result * 2;
});

myPromise.then(function(result) {
alert(result); // 1
return result * 2;
});

myPromise.then(function(result) {
alert(result); // 1
return result * 2;
});

A

all together when resolve() is called in the promise

34
Q

JS: to loop through the values of an object, type

{name: ‘string’, name: ‘string’}

A

let obj = {name: ‘string’, name: ‘string’}

for (const key in obj) {
console.log(obj[key])
}

or better

for (const key in obj) {
    if (obj.hasOwnProperty(key)) {
        console.log(obj[key]);
    }
}
35
Q

JS: to loop through the items of an array, type

A

let obj = [1, 2, 3]

for (const item of obj) {
console.log(item)
}

note: using for..in loops through the indexes

36
Q

JS: When you instantiate a promise, even into a variable,

A

it starts running immediately.

note, the promise methods are .then and .catch

37
Q

JS: setTimeout() can take an optional third argument which is

A

the value to be passed into the function

i.e.

var myPromise = new Promise(function(resolve, reject) {
    setTimeout(resolve, 500, 'string');
});
38
Q

JS: Promise.race([myPromise1, myPromise2]) passes into the .then() the

A

resolve value of the first promise to resolve.

39
Q

JS: Promise.all([myPromise1, myPromise2]) passes into the .then()

A

an array with all the resolve values.

40
Q

JS: The difference between == and === is

A

== is type converting equality and === is strict equality

Null==Undefined is true
Null===Undefined is false
‘5’ == 5 is true
‘5’ === 5 is false

41
Q

python: The namespace is

A

the dictionary that holds all the accessible environment variables names and values

42
Q

JS: Prototypal inheritance is

A

when you create a new function, it inherits properties and methods from its prototype which is called function, and that inherits from its prototype that is called object. When you call a property or method it looks up the prototype chain to find a property or method with that name.

You can add a function to a constructor function by typing
ConstructorFunctionName.prototype.newFuncName = function() {…}

43
Q

python: To create a virtual environment, type

A

python3 -m venv /path/

cd /path/
source bin/activate

and to close it
source bin/activate

44
Q

python: the difference between pass and continue is

A

continue forces the loop to skip to next iteration and pass does nothing.

45
Q

Python: To insert a list into the middle of another list, type

A

list_1.insert(4, list_2)

The 4 denotes the index to insert at

46
Q

Python: To remove one item from a list by its index, type

A

del my_list[2]

47
Q

Python: To slice a list or string by returning steps that skip, type

A

my_list[1::2], Add an extra colon

48
Q

Python: To return a string or list backwards using slice, type

A

my_string[::-1], make the skipping step a negative, and swap the start and end range [10:1:-1]

49
Q

Python: The difference between find and index is

A

str.find returns -1 when it does not find the substring.

While str.index raises ValueError:

50
Q

Python: To return a tuple with the index and value from an iterable, type

A

enumerate(my_iterable)

51
Q

Python: To apply a predefined function to every item in a list, in a short way, type

A

map(my_function, my_list)