20 Oct 2019
set.add('1');
set.add('1');
API’s GET, PUT and DELETE should be idempotent
ephemeral: temporary
predicate: a function that returns a boolean
function isPhoneNumber(str) {
...
return true;
...
return false;
}
memoization: caching the return value of a function
serialization: converting an object to a more generic format (eg. JSON) so that it can be used somewhere else, eg. JavaScript object → JSON → Python object
25 Jun 2019
class Observable {
constructor(functionThatTakesObserver) {
this._functionThatTakesObserver = functionThatTakesObserver;
}
subscribe(observer) {
return this._functionThatTakesObserver(observer)
}
}
let myObservable = new Observable(observer => {
setTimeout(() => {
observer.next("Got data")
observer.complete()
}, 1000)
})
let myObserver = {
next(data) {
console.log(data);
},
error(e) {
console.log(e);
},
complete() {
console.log("Request complete")
}
}
myObservable.subscribe(myObserver)
// Output:
// (1 second) Got data
// (1 second) Request complete
Everything you can do with a Promise you can do an Observable. Everything you can do with an observable you can’t necessarily do with a Promise. An observable can call next()
multiple times, whereas a promise either resolves or rejects, it can’t emit multiple values.
12 Jun 2019
Arrow functions allow shorter syntax, for example:
const foo = () {
return "bar";
}
vs
const foo = () => {
return "bar";
}
or even
const foo = () => "bar";
If a function has only one parameter you can skip the parentheses:
const timesTwo = val => 2 * val;
this
→ In regular functions this
keyword represents the object that called the function.
→ In arrow functions this
keyword represents the object that defined the arrow function.
Regular function:
javascriptCopy code
const obj = {
name: 'John',
regularMethod: function() {
console.log(this.name);
}
};
obj.regularMethod(); // Output: John
Arrow function:
javascriptCopy code
const obj = {
name: 'John',
arrowMethod: () => {
console.log(this.name);
}
};
obj.arrowMethod(); // Output: undefined (the arrow function inherits the `
17 May 2019
The syntax is as follows:
variable ||= value
This is equivalent to writing:
variable = variable || value
Works in JavaScript and Ruby.
26 Feb 2019
filter()
is applied to each element and if it returns True, the element is selected.filter(function, iterable)
def check_even(number):
if number % 2 == 0:
return True
return False
numbers = [1, 2, 3, 4]
even_numbers_iterator = filter(check_even, numbers)
even_numbers = list(even_numbers_iterator)
print(even_numbers)
# Output: [2, 4]
numbers = [1, 2, 3, 4]
even_numbers_iterator = filter(lambda: x: (x%2 == 0), numbers)
When None
is used, all elements that are truthy values (gives True
if converted to boolean) are extracted.
some_list = [1, 'a', 0, False, True. '0']
filtered_iterator = filter(None, numbers)
filtered_list = list(filtered_iterator)
print(filtered_list)
# Output: [1, 'a', True, '0']
12 Feb 2019
Secure Shell or Secure Socket shell is an application layer protocol.
→ Supports both password and key-based authentication
→ Encrypts data communication between computers
→ By default the server listens on HTTP port 22
ssh-keygen
: new auth key pair for SSHssh-copy-id
: copies, installs and configures an SSH key on a serverscp
: an SSH-secured version of the RCP protocol, lets the user copy files from one machine to anothersftp
: an SSH-secured version of the FTP protocol, used to share files on the internetssh-keygen -t rsa
The -t flag means the type of key we want to generate.
09 Jan 2019
ssh-keygen -t ed25519
27 Dec 2018
"Zero-day"
- the developer has only just learned about the flaw and has zero days to fix it.
Zero-day attack: when hackers exploit the flaw before the developers have a chance to address it.
Zero-day vulnerability: a software flaw that discovered by attackers before the vendor/developer has become aware of it.
Zero-day exploit: the method/technique hackers use to attack a system.
28 Nov 2018
A sequence of numbers and letters that serves to ensure a downloaded file doesn’t have errors.
If you know the checksum of an original file, you can use a checksum utility to confirm your copy is identical.
To produce a checksum you run a program that puts the file through an algorithm (MD5, SHA-1, SHA-256, SHA-512 etc.), and a cryptographic hash function will produce a string of a fixed length.
This works cause small changes in the file will produce very different looking checksums.
Because of collisions, you shouldn’t rely on MD5 or SHA-1 to check that a file is authentic, just to check corruption.
There haven’t been any repots of an SHA-256 collision yet.
20 Oct 2018
POSIX - Portable Operating System Interface
→ A family of standards specified by IEEE for maintaining compatibility among operating systems
→ Any software that conforms to POSIX standards should be compatible with other operating systems that adhere to POSIX
There are currently more than 20 standards under the POSIX umbrella.
POSIX standards define:
ls
, cp
, and grep
, along with their command-line options and behavior. /bin
, /usr
, and /lib
. 03 Oct 2018
Database schema defines how data is organized within a relational database (logical constraints such as, table names, fields, data types, and the relationships between these)
A database schema = “blueprint” of a database which describes how the data may relate to other tables or other data models. Schema does not actually contain data.
This process of database schema design is also known as data modelling.
29 Jun 2018
Teams should first agree on a commit message convention:
Limit the subject line to 50 characters
→ If you’re having a hard time summarizing you might be committing too many changes at once.
Capitalize the subject line
Do not end the subject line with a period
Use the imperative mood in the subject line
Wrap the body at 72 characters
Use the body to explain what and why vs. how
→ Focus on making clear the reasons why you made the change - the way it things worked before the change (and what was wrong with that), the way they work now and why you decided to solve it the way you did.
For example
Fix typo (what) in introduction to user guide (where).
git shortlog
groups commits by user
01 Jun 2018
10 May 2018
Generator functions are a special kind of function that return a lazy generator. Unlike lists, lazy generators do not store their contents in memory. We use them to work with data streams or large files (eg. CSV files).
In the following code open(file_name, "r")
returns a generator, but file.read()
loads the whole file into memory.
open(file_name, "r"):
result = file.read().split("\n")
Instead, we can yield
each row instead of returning it:
for row in open(file_name, "r"):
yield row
def infinite_sequence():
num = 0
while True:
yield num
num += 1
We can use it in a for-loop:
for i in infinite_sequence():
print(i, end=" ")
# Output: 0 1 2 3 4 5 6 7 8 ...
Or we can also call next()
:
next(gen)
# Output: 0
next(gen)
# Ouptut: 1
Similar to list comprehension but with generators.
csv_gen = (row for row in open(file_name))