< Return to Video

Lecture 10: Potpourri (2020)

  • 0:01 - 0:03
    Hi, can everyone hear me okay?
  • 0:03 - 0:07
    Okay, so welcome back to
  • 0:07 - 0:09
    the missing semester of your CS education,
  • 0:09 - 0:12
    today we're having as a
    lecture topic "potpourri"
  • 0:12 - 0:15
    It's gonna be some miscellaneous
    combination of topics
  • 0:15 - 0:19
    that we the instructors find
    that are interesting
  • 0:19 - 0:21
    But none of them were on their own lecture
  • 0:21 - 0:25
    because they're certain topics that
    we just want you to know about
  • 0:25 - 0:28
    because they can be really helpful
  • 0:29 - 0:33
    And since we're not gonna delve into
    a lot of detail in the topics
  • 0:33 - 0:37
    If you're more interested about them just
    feel free to come and ask us questions
  • 0:37 - 0:41
    at the end or as we go over
    them in the lecture
  • 0:41 - 0:46
    So the first thing I want to talk about
    is keyboard re-mappings
  • 0:46 - 0:48
    So by now you probably realized that
  • 0:48 - 0:52
    we have encouraged you to use the
    keyboard as your main input method
  • 0:52 - 0:55
    so for example, when we went
    into the editors lecture,
  • 0:55 - 1:00
    one of the main ideas of Vim was using
    your keyboard as much as possible
  • 1:00 - 1:05
    so you don't have to rely on going to the
    mouse because going to the mouse is slow
  • 1:05 - 1:08
    And the thing is your keyboard, as with
    many things in your computer
  • 1:08 - 1:12
    is nothing kind of magical,
    it can be configured
  • 1:12 - 1:17
    And it's worth configuring because a lot
    of the defaults might not be optimal
  • 1:17 - 1:22
    The most simple modification that you
    can do is just to remap keys
  • 1:22 - 1:26
    So one of the things we alerted
    in the editor lecture
  • 1:26 - 1:28
    is the Caps Lock key is a really good key
  • 1:28 - 1:31
    because it's kind of right
    in the home row
  • 1:31 - 1:35
    and it's kind of large and there,
    but it's not useful
  • 1:35 - 1:38
    You'll probably realize that you don't
    use your Caps Lock as often
  • 1:38 - 1:40
    as when you'd want to use that
  • 1:40 - 1:43
    So you can just remap your
    Caps Lock key
  • 1:43 - 1:44
    to something more useful as we mentioned
  • 1:44 - 1:46
    like Escape if you're a Vim user
  • 1:46 - 1:49
    or like Control if you're an Emacs user
  • 1:49 - 1:52
    or useful re-mappings, like a lot of the
  • 1:52 - 1:56
    upper row 'F' function keys,
    or like Print Screen
  • 1:56 - 1:59
    You can remap them for example
    to your media key
  • 1:59 - 2:01
    so like when you type Print Screen,
  • 2:01 - 2:04
    you probably don't have to
    do Print Screen that often
  • 2:04 - 2:07
    but you probably want to play
    or pause your music
  • 2:08 - 2:11
    And pretty much every operating system has
  • 2:11 - 2:14
    some tools that you can use
    to configure this
  • 2:14 - 2:16
    I'm not gonna go into the details
  • 2:16 - 2:19
    but there's some of them
    listed in the notes
  • 2:20 - 2:23
    Erm... Let me check
  • 2:23 - 2:27
    Oh yeah, another thing that you can
    do with keyboard re-mappings is
  • 2:27 - 2:29
    that you can do more complex combinations
  • 2:29 - 2:33
    You can have a combination of keys
    mapped to some action
  • 2:33 - 2:36
    So for example, I have keyboard
    re-mappings that
  • 2:36 - 2:40
    whenever I do Ctrl+Enter, I open
    a new terminal window
  • 2:40 - 2:43
    because that's a thing I do
    fairly often and
  • 2:43 - 2:46
    by default on Mac there is no
    key binding to do that
  • 2:46 - 2:49
    or Ctrl+Shift+Enter will open a
    new browser window,
  • 2:49 - 2:51
    another operation that I do
    on a daily basis
  • 2:51 - 2:56
    So I don't have to grab my mouse
    and go to Chrome to do that
  • 2:56 - 3:00
    You can also do remapping to
    perform actions
  • 3:00 - 3:03
    If you don't want to be typing your
    password all the...
  • 3:03 - 3:04
    Sorry, not your password
  • 3:04 - 3:07
    Your Email or your password,
    or for example, your MIT ID
  • 3:07 - 3:09
    like, you may not remember it by heart
  • 3:09 - 3:12
    then you can just have a
    keyboard combination that
  • 3:12 - 3:17
    will just perform the action of
    pasting that text
  • 3:20 - 3:21
    Lastly, there are more...
  • 3:21 - 3:25
    Right now it looks like you just have
    to do some function of
  • 3:25 - 3:28
    "this is the keys that you press and
    this is the action that happens"
  • 3:28 - 3:32
    But actually there are more complex
    keyboard combinations, and
  • 3:32 - 3:37
    as you go through you'll learn
    so you can do keyboard sequences
  • 3:37 - 3:39
    So for example when we were
    dealing with tmux,
  • 3:39 - 3:41
    in tmux there was this notion of
  • 3:41 - 3:46
    first you press Ctrl+A or Ctrl+B, like
    you press some prefix
  • 3:46 - 3:50
    and then some other key and
    that means something
  • 3:50 - 3:51
    A lot of these softwares allow that
  • 3:51 - 3:56
    So for example, in my keyboard, since
    I'm not using Caps Lock at all, but
  • 3:56 - 4:00
    every so often I have to use when my
    undergrad has some software that
  • 4:00 - 4:03
    relied on Caps Lock for changing modes
  • 4:03 - 4:09
    Then I can press Shift five times
    in a row quickly, and then
  • 4:09 - 4:12
    this software that is in the middle
    interpreting these commands and
  • 4:12 - 4:17
    remapping to some other, will send a
    single Caps Lock command for that
  • 4:18 - 4:20
    Some more examples of that is that
  • 4:20 - 4:28
    I mentioned that you can use your
    Caps Lock key to map to Escape or Control
  • 4:28 - 4:30
    but you actually can remap it to both
  • 4:30 - 4:31
    So in my computer when
  • 4:31 - 4:35
    I just tap the Caps Lock key, that's
    interpreted as an Escape
  • 4:35 - 4:40
    However if I press it and hold it,
    this software can understand the
  • 4:40 - 4:42
    difference between quickly pressing it and
  • 4:42 - 4:46
    just holding it for using in
    combination with some other key
  • 4:46 - 4:49
    and then in that case
    it's mapped to Control
  • 4:49 - 4:52
    So a lot of these more
    advanced configurations are
  • 4:52 - 4:55
    supported on a lot of these tools
  • 4:56 - 5:00
    As I mentioned we have a
    short list of good defaults
  • 5:00 - 5:05
    for these programs for
    Windows, Mac OS and Linux
  • 5:06 - 5:08
    Any questions on this topic?
  • 5:13 - 5:17
    Okay, now I'm going to cover an
    unrelated topic to keyboard mappings
  • 5:17 - 5:18
    [chuckles]
  • 5:18 - 5:21
    We're going to see a lot of these
    unrelated transitions in this lecture
  • 5:21 - 5:24
    And it's the concept of "daemons"
  • 5:24 - 5:25
    So probably you have...
  • 5:25 - 5:29
    Maybe if you are not familiar with
    the world, it might seem alien,
  • 5:29 - 5:31
    but the concept of daemon
    you're pretty familiar with
  • 5:31 - 5:33
    Most computers when you are running them
  • 5:33 - 5:37
    there's software that you start and run,
  • 5:37 - 5:39
    like the commands that we have been seeing
  • 5:39 - 5:43
    You'd type "ls" and then you're
    calling the List command
  • 5:43 - 5:47
    The "ls" command executes because you
    asked it to execute and then it finishes
  • 5:47 - 5:52
    But a lot of other programs are just
    running as background processes
  • 5:52 - 5:55
    and they're just executing
    in the background
  • 5:55 - 5:57
    and waiting for events to happen
  • 5:57 - 6:01
    or enabling some sort of functionality
    in your computer
  • 6:02 - 6:05
    Examples of these processes may be
    like your Network Man[ager],
  • 6:05 - 6:08
    like the part of your computer
    that is managing the network
  • 6:08 - 6:12
    or the part of your computer
    that is managing the display
  • 6:12 - 6:14
    Things like that
  • 6:15 - 6:19
    You will see that a lot of what
    is enabled by daemons is
  • 6:19 - 6:21
    usually programs that end with a 'd'
  • 6:21 - 6:26
    So for instance, when you are
    SSHing into a computer,
  • 6:26 - 6:30
    the receiving computer has to
    have a SSH daemon
  • 6:30 - 6:33
    and the program is called "sshd"
  • 6:33 - 6:35
    and if this program is not running then
  • 6:35 - 6:38
    there's no way for me
    to SSH into the computer
  • 6:38 - 6:41
    If the program is running, then
    that program will be listening
  • 6:41 - 6:44
    and when you do SSH to that server,
  • 6:44 - 6:48
    then some incoming request
    is gonna enter the computer
  • 6:48 - 6:53
    the computer is gonna send it to this
    daemon that is running in the background
  • 6:53 - 6:56
    and then the daemon is gonna check
    whether you have authorization,
  • 6:56 - 7:01
    and if so, it's gonna start some login
    shell that you can start executing from
  • 7:01 - 7:07
    And different OSes handle this
    somewhat differently
  • 7:07 - 7:11
    The main idea is they all have
    some sort of system daemon
  • 7:11 - 7:15
    that responds a lot of
    these smaller daemons
  • 7:15 - 7:19
    In Linux, which is one of the OSes that
    we are choosing for lot of the examples,
  • 7:19 - 7:24
    the tool that you're using
    is the "systemd"
  • 7:24 - 7:29
    Again, first the system daemon is gonna
    start a lot of these processes
  • 7:29 - 7:33
    and if you use this "systemctl" command,
  • 7:33 - 7:37
    you can check for the status
    of different daemons
  • 7:37 - 7:41
    you can check for which ones are running,
  • 7:43 - 7:47
    you can ask it to start processes,
    to stop them
  • 7:47 - 7:50
    This is kind of an once-off operation
  • 7:50 - 7:53
    You can also enable it
    and then disable them,
  • 7:53 - 7:57
    which will tell the system
    to run them at boot
  • 7:57 - 8:00
    or stop running the boot
    if they were enabled
  • 8:01 - 8:07
    And perhaps more interestingly, you can
    configure your own "systemd" units
  • 8:07 - 8:13
    So, so far all the examples are a lot
    of what the computer has to do,
  • 8:13 - 8:18
    but say you want to run a web server.
    One solution, you could just like,
  • 8:18 - 8:23
    every time you start your computer
    you could open a tmux session
  • 8:23 - 8:25
    and then execute the command,
  • 8:25 - 8:30
    but that's not really the way that your
    computer expects daemons to be run
  • 8:30 - 8:33
    The way your computer expects
    daemons to be run is
  • 8:33 - 8:35
    by using some sort of "systemd" unit
  • 8:35 - 8:41
    It's like a configuration that tells
    "systemd" how to execute this process
  • 8:41 - 8:44
    So an example of this is...
  • 8:45 - 8:48
    Here's a very simple example
  • 8:48 - 8:51
    So what is happening here is
  • 8:51 - 8:57
    we're describing to "systemd" what needs
    to be done for this program to execute.
  • 8:57 - 9:01
    This example is just running
    a simple Python app
  • 9:01 - 9:05
    You can think of it as a web server that
    can be implemented using
  • 9:05 - 9:08
    some Python web server library.
    And here we're saying
  • 9:08 - 9:13
    this is the description, we're
    saying after, like this is important
  • 9:13 - 9:17
    "Systemd" has a list of
    services that have to start
  • 9:17 - 9:19
    Like, all these daemons have to be started
  • 9:19 - 9:23
    but maybe there are dependencies
    between these daemons, so here
  • 9:23 - 9:28
    we're saying "no, you should only start
    this after the network has been set up"
  • 9:28 - 9:31
    because otherwise how will you even try to
  • 9:31 - 9:35
    configure our web server if I cannot
    listen to a network port?
  • 9:35 - 9:39
    And then we are defining what
    users should run this, because
  • 9:39 - 9:42
    you may want to run this as
    your user, or maybe other user,
  • 9:42 - 9:45
    or maybe the root user
    should be running this,
  • 9:45 - 9:49
    and then what command to run
    and under what directory
  • 9:49 - 9:51
    And whenever you have this,
  • 9:51 - 9:55
    there can be small corner cases that
    you might have to debug, but
  • 9:55 - 9:58
    this is kind of the core idea and
    it can be really useful to
  • 9:58 - 10:01
    automate the process of
    running processes in the background
  • 10:02 - 10:06
    A small side note to this is
    the fact that if you just want
  • 10:06 - 10:11
    to run a command every so often,
    like in some periodicity,
  • 10:11 - 10:15
    say every morning I want to
    do something in my computer,
  • 10:15 - 10:20
    you could write a daemon that just does
    something and then sleeps for a day, but
  • 10:20 - 10:27
    actually Linux and Mac OS have already a
    daemon that does this called "crond"
  • 10:27 - 10:31
    and "crond" will take another type of
    configuration file where you can say
  • 10:31 - 10:36
    oh, I want to run a command
    every day at 8 AM,
  • 10:36 - 10:38
    or I want to run a command
    every 5 minutes,
  • 10:38 - 10:42
    and it will just check for
    this event and execute it
  • 10:42 - 10:45
    And with a lot of things
    you will find that
  • 10:45 - 10:48
    there are already daemons that
    have been configured for that
  • 10:48 - 10:52
    Any questions regarding daemons?
  • 10:54 - 10:57
    [student talking indistinctly]
  • 10:58 - 11:00
    So the question is whether there is
  • 11:00 - 11:03
    a folder in the computer
    where all of these are
  • 11:03 - 11:05
    So yeah, like yes and no
  • 11:05 - 11:09
    Some of these configuration files are
    in a couple of different folders
  • 11:09 - 11:13
    depending on whether they are
    system daemons or they are user daemons
  • 11:13 - 11:18
    Here you can see at the very first line
    is where you will place this
  • 11:18 - 11:23
    for the system daemon to recognize
    that it has been installed
  • 11:23 - 11:26
    but if you just want to list
    all the daemons that are running,
  • 11:26 - 11:30
    in Linux for example, you can just do
    "systemctl status"
  • 11:30 - 11:34
    and that's gonna print
    a tree of all the systems
  • 11:34 - 11:38
    and which daemon was spawned
    by which other daemon
  • 11:38 - 11:42
    and a lot of them will be
    spawned directly by "systemd"
  • 11:44 - 11:49
    The next topic is going to be
    file systems in user space
  • 11:49 - 11:56
    So, kind of a quick intro to this is the
    fact that whenever you're using a modern..
  • 11:56 - 11:58
    Oh, yeah, sorry
  • 11:58 - 12:02
    And whenever you're using a
    modern operating system,
  • 12:02 - 12:07
    you are not tied to a specific file system
  • 12:07 - 12:11
    So modern systems are fairly modular
    and you can for example,
  • 12:11 - 12:16
    in Linux there are different file systems
    that you can use, and
  • 12:16 - 12:23
    the way this works is because the kernel,
    which is what is running most of the
  • 12:23 - 12:30
    operating system, has some modules that
    know how to interact with a file system
  • 12:30 - 12:37
    So usually when you do something
    like "touch foobar",
  • 12:39 - 12:45
    this is happening at a user level
  • 12:45 - 12:50
    and then this is going through
    to the kernel level
  • 12:50 - 12:55
    and there is some kind of
    layer here that is checking
  • 12:55 - 13:00
    where this action is happening to
    figure out what file system it is under
  • 13:00 - 13:03
    So for example, you will
    have multiple disks
  • 13:03 - 13:05
    and all the different disks
    have different file systems,
  • 13:05 - 13:10
    so the kernel has to figure out which
    file system operations to use,
  • 13:10 - 13:18
    and say this file might be in an "Ext4",
    which is the most common Linux one,
  • 13:18 - 13:24
    then whenever you do "touch foobar",
    the kernel will hear that
  • 13:24 - 13:28
    and then it will try to figure out like,
    oh, this lives in an Ext4 file system and
  • 13:28 - 13:36
    it will perform the associated instruction
    for creating a file in an Ext4 file system
  • 13:36 - 13:39
    However, the caveat of having
    a system like this is
  • 13:39 - 13:45
    right now I cannot have user code
    that defines how to create a file
  • 13:45 - 13:48
    and that might be kind of
    useful in some cases
  • 13:48 - 13:53
    Say I want to have a file system that
    every time someone creates a file,
  • 13:53 - 13:58
    it sends me an email, so I can know that
    people are creating these files
  • 13:58 - 14:02
    Here I cannot modify
    the kernel to add this
  • 14:02 - 14:06
    So the solution to this is
    something called "FUSE"
  • 14:06 - 14:14
    And FUSE is a way of having
    file systems in user space
  • 14:14 - 14:15
    So what FUSE will do is,
  • 14:15 - 14:25
    if this file instead of being in Ext4,
    if this file is in a FUSE file system,
  • 14:25 - 14:32
    FUSE will forward this operation to
    some other part of user call
  • 14:32 - 14:35
    that will say "oh, create this file"
  • 14:35 - 14:41
    And here I can have the part of the code
    that sends an email to me,
  • 14:41 - 14:43
    saying "oh, this file has been created"
  • 14:43 - 14:47
    And in case you want to
    still create the file,
  • 14:47 - 14:54
    it can forward back the request
    to do some more kernel operations
  • 14:54 - 14:58
    It might not seem really practical,
    but this is just the theory
  • 14:58 - 15:02
    In practice, why this is useful is because
  • 15:02 - 15:06
    now you can have user level code
    that executes arbitrary actions
  • 15:06 - 15:09
    when you try to perform
    file system operations
  • 15:10 - 15:15
    A really Interesting example of this
    is called "SSHFS"
  • 15:20 - 15:23
    On an SSHFS FUSE file system,
  • 15:23 - 15:28
    whenever you try to create,
    open, read, write to a file,
  • 15:28 - 15:31
    instead of trying to do that
    to a local file,
  • 15:31 - 15:35
    it has an SSH connection
    to a remote server
  • 15:35 - 15:39
    So if I try to create a file here,
    It will use that SSH connection to
  • 15:39 - 15:43
    forward that operation to
    the remote system
  • 15:43 - 15:45
    and then it will perform it there
  • 15:45 - 15:50
    So to all my local computer, to the rest
    of the programs running in my computer,
  • 15:50 - 15:54
    there is this path that looks
    like it is here, but
  • 15:54 - 15:58
    all the operations that are performed
    to the path are forwarded
  • 15:58 - 16:00
    to the remote file system
  • 16:00 - 16:04
    And with this idea, you will get
    some examples in the notes,
  • 16:04 - 16:08
    and you will find more online,
    of ways people have
  • 16:08 - 16:11
    leveraged this capability to do
    fairly interesting file systems
  • 16:11 - 16:14
    So for example, if instead of having SSH,
  • 16:14 - 16:19
    you don't care about SSH because
    you use Dropbox or Google Drive,
  • 16:19 - 16:24
    it's fine, people have implemented
    FUSE file systems that will mount locally
  • 16:24 - 16:27
    and every time you try to do
    an operation locally,
  • 16:27 - 16:31
    actually it goes to one of these
    cloud storage providers
  • 16:31 - 16:35
    so you can also use something like
    Amazon S3, or Google Cloud Storage,
  • 16:35 - 16:42
    that don't have the same
    kind of UI system
  • 16:42 - 16:45
    that we synchronize, as
    Dropbox or Google Drive
  • 16:46 - 16:51
    Another application of this that is not
    related to doing something remotely,
  • 16:51 - 16:53
    is something like
    an encrypted file system
  • 16:53 - 16:58
    You may have a file system that
    every time you try to write to a file,
  • 16:58 - 17:02
    you will try to write it in plain text,
    but it will capture that operation
  • 17:02 - 17:05
    it will encrypt on the go,
  • 17:05 - 17:08
    and then it will save it as a
    regular file in your file system,
  • 17:08 - 17:10
    but that's actually encrypted
  • 17:10 - 17:15
    And once you dismount the file system,
    once you remove the FUSE connection,
  • 17:15 - 17:19
    all that is left in your computer are just
    regular files that are encrypted
  • 17:20 - 17:27
    The last topic I wanna cover is backups
    and some good practices about them
  • 17:29 - 17:34
    The main idea is that for every
    file that you care about,
  • 17:34 - 17:36
    if you don't have a backup of that file,
  • 17:36 - 17:38
    if you don't have a backup
    stored of that file,
  • 17:38 - 17:40
    you can pretty much lose it at any moment
  • 17:40 - 17:43
    There are many different failure scenarios
  • 17:43 - 17:49
    One of them is just hardware failure.
    So your hard drive can fail at any moment
  • 17:49 - 17:55
    So if you are just making a copy of your
    files in the same drive, that's not useful
  • 17:55 - 17:58
    If your hard drive fails,
    the files are gone
  • 17:58 - 18:02
    The same goes if you have an external
    drive where you are making a copy,
  • 18:02 - 18:07
    but if you are storing everything in your
    home, and your home burns down...
  • 18:07 - 18:12
    Which yes, it's unlikely, but
    if it happens you just lost all your data
  • 18:12 - 18:16
    So you'd have some sort of
    off-site backup for having this solution
  • 18:17 - 18:20
    Another thing to take into account is that
  • 18:20 - 18:23
    synchronization or mirroring options
    are not backups
  • 18:23 - 18:26
    So Google Drive, Dropbox
    that I was mentioning,
  • 18:26 - 18:30
    they will just propagate whatever is
    happening in your computer
  • 18:30 - 18:33
    This goes also for
    hardware mirroring, like RAID
  • 18:33 - 18:35
    They are just making a copy
  • 18:35 - 18:37
    If you accidentally delete a file,
  • 18:37 - 18:42
    or someone maliciously deletes your files,
    or encrypts them using some ransomware,
  • 18:42 - 18:47
    then you might have a copy, but
    you have a copy of the same useless data
  • 18:47 - 18:51
    You actually have to have a solution of
    how you're running your backups
  • 18:51 - 18:53
    And you should be asking yourself
  • 18:53 - 19:01
    what actually someone needs to know/have
    about you in order to delete all your data
  • 19:01 - 19:09
    And we have linked different softwares
    in the notes about how to do this
  • 19:09 - 19:13
    The last thing I want to mention about
    backups is that a lot of the time
  • 19:13 - 19:17
    when you think about backups, you just
    think about the local files
  • 19:17 - 19:21
    and like, all my photos and my tax return,
    and how can I make a backup of that?
  • 19:21 - 19:25
    But increasingly in the modern age,
    there are more and more web applications
  • 19:25 - 19:29
    and a lot of data might only live
    in some cloud provider,
  • 19:29 - 19:31
    like for example if you have Webmail,
  • 19:31 - 19:33
    and you're not synchronizing it
    to your computer,
  • 19:33 - 19:37
    It's only living in
    that provider's servers
  • 19:37 - 19:39
    And if you don't have a copy for that
  • 19:39 - 19:42
    and for some reason you
    lose access to that account
  • 19:42 - 19:44
    because you forgot your password,
    you got hacked,
  • 19:44 - 19:49
    they think you have violated the
    terms of service... All that data is gone
  • 19:49 - 19:53
    So you should look into some tools
    that people have developed
  • 19:53 - 19:58
    for making offline copies of all that data
  • 19:58 - 20:01
    so you can make regular backups of that
  • 20:01 - 20:05
    And that kind of ends this
    short section on backups
  • 20:05 - 20:07
    Any questions so far?
  • 20:10 - 20:13
    (student) When you said that
    a hard drive can fail at any time
  • 20:13 - 20:15
    Is there a reason for it to fail?
  • 20:15 - 20:17
    [unintelligible]
  • 20:17 - 20:21
    Like if I have my external hard drive
    sitting at my parents house or something
  • 20:21 - 20:26
    And my computer here, is that enough?
    Or any drive can just fail?
  • 20:26 - 20:30
    (Jose) Any drive can fail at any moment.
    Like we don't...
  • 20:30 - 20:34
    Different media have
    different rates of failure
  • 20:34 - 20:37
    and there are really good
    statistics online
  • 20:37 - 20:38
    So for example,
  • 20:38 - 20:42
    spinning hard drives have a higher
    rate of failure than SSDs for example,
  • 20:42 - 20:44
    like Solid-State Drives
  • 20:44 - 20:47
    And what's another case?
    Or like CD drives for example
  • 20:48 - 20:54
    But if you drop a hard drive it's a
    higher rate of that failing, of course
  • 20:54 - 21:00
    But in general we don't really have
    an end-all solution
  • 21:00 - 21:02
    for saying "this media is not gonna fail"
  • 21:02 - 21:08
    Like pretty much, like SD cards, SSDs,
    hard drives, CDs, degrade with time
  • 21:08 - 21:12
    Pretty much every data is kind of
    bound to this degradation
  • 21:12 - 21:16
    or like this fact that it could
    be lost at any moment
  • 21:16 - 21:19
    And you should also know that
    data can become corrupted,
  • 21:19 - 21:24
    your disk might look like it's okay,
    but maybe some files were corrupted
  • 21:24 - 21:26
    and something like
    synchronization techniques,
  • 21:26 - 21:30
    like Google Drive or Dropbox,
    will propagate that corruption
  • 21:30 - 21:35
    And by the time that you realize that
    things have gone wrong it's maybe too late
  • 21:40 - 21:46
    (Jon) Alright, we're gonna continue this trend of jumping between random topics and talk about APIs
  • 21:47 - 21:53
    So so far we've really been talking about how do you do things more efficiently locally on your computer?
  • 21:53 - 21:59
    Like I want to accomplish this task more efficiently. How do I like configure my editor? How do I use my shell?
  • 21:59 - 22:04
    But one thing you should realize is that very often you can integrate with the outside world as well
  • 22:04 - 22:08
    Most services that you interact with in your day-to-day provide some kind of API
  • 22:08 - 22:12
    For you to interact with the data that they store or the services that they provide
  • 22:12 - 22:15
    And usually those APIs are pretty well documented
  • 22:16 - 22:22
    If you looked at the APIs for things like Facebook, or Twitter, or Google Drive, or Gmail
  • 22:22 - 22:29
    Many of these have interfaces that you can interact with in order to use those services from your local machine
  • 22:29 - 22:34
    What's really neat is that you can often combine this with some of the stuff that we've talked about in lecture so far
  • 22:34 - 22:38
    Like for example in the Data Wrangling lecture, we looked at how you can create
  • 22:38 - 22:43
    These pipelines to extract data from some source that has a different format than you expected
  • 22:44 - 22:48
    So for instance, the US government has a free service
  • 22:48 - 22:52
    Where you can request the weather forecast for any given location in the US
  • 22:52 - 22:56
    And what you do is there is a URL that you request
  • 22:56 - 23:01
    And if you set the right parameters in that URL and then just fetch it, what you get back is JSON
  • 23:01 - 23:06
    Which is sort of a well-defined data format that you can then parse
  • 23:06 - 23:11
    And you can extract things like your 14-day weather forecast
  • 23:11 - 23:15
    And maybe you then pipe that into your shell and produce some kind of like
  • 23:15 - 23:18
    Handy alias in your terminal that's just gonna print...
  • 23:18 - 23:23
    Of some handy reference for the next 14 days of weather in whatever location you were in
  • 23:24 - 23:28
    These are things you can pretty easily construct and there's some notes...
  • 23:28 - 23:32
    There are some notes in the notes about how you might go about this
  • 23:32 - 23:38
    In general when you interact with these APIs, you're going to be using URLs of one form or another
  • 23:38 - 23:41
    And the exact format varies from service to service
  • 23:41 - 23:45
    But in general the URL is going to contain some set of parameters
  • 23:45 - 23:50
    But ultimately you're just gonna issue a web request to them and you're gonna get data back in some format
  • 23:50 - 23:55
    One command you should be aware of for interacting with these types of things is one called "curl"
  • 23:55 - 23:59
    So curl is a program that you invoke, you give it a URL
  • 23:59 - 24:01
    And it just fetches that URL and gives you back the response
  • 24:01 - 24:04
    What you do with that response is entirely up to you
  • 24:04 - 24:09
    Maybe you pipe it through a program like "gq". Sorry, "jq"
  • 24:09 - 24:15
    So jq is a JSON query tool that lets you take in data that's formatted as JSON
  • 24:15 - 24:20
    And then write a query over it to extract data that you're interested in
  • 24:20 - 24:25
    And this is one of the ways in which you can layer these tools to extract the data that you're interested in
  • 24:25 - 24:30
    Some of these services also require that you authenticate in one way or another
  • 24:30 - 24:33
    Like for example if you want to interact with a Facebook API
  • 24:33 - 24:39
    You need to have some authenticated token that proves who you are as far as Facebook is concerned
  • 24:39 - 24:44
    Otherwise, they can't say whether you're allowed to say, create a post as a given user
  • 24:44 - 24:48
    Very often these things are gonna use something called "OAuth", although not always
  • 24:48 - 24:52
    And you should look at the documentation for every service you care about
  • 24:52 - 24:56
    In general though you will get some kind of secret token back from the service
  • 24:56 - 24:59
    That you have to include in the requests that you make to them
  • 24:59 - 25:04
    Either in the URL or in additional sort of web headers, which you can also send with curl
  • 25:04 - 25:11
    Keep in mind though that these tokens are secret. They are another representation of your user
  • 25:11 - 25:14
    And anyone who gets their hand on them can basically pretend to be you
  • 25:14 - 25:17
    They can do whatever you can do with that token
  • 25:17 - 25:22
    So keep this in mind, don't stick them in your "dotfiles" and then push them onto GitHub
  • 25:22 - 25:26
    That will land you in trouble. You should think of them as a password
  • 25:26 - 25:29
    There are also really neat tools online for integrating services
  • 25:29 - 25:33
    So there's a service called "If This Then That"
  • 25:33 - 25:39
    Which basically provides integrations with a bunch of different services and lets you chain them together
  • 25:39 - 25:42
    And then also access them partially locally if you wish
  • 25:42 - 25:44
    This is something that's worth looking into
  • 25:44 - 25:49
    If there's a particular service you would like to interact with in a more efficient manner
  • 25:50 - 25:53
    Any questions about APIs?
  • 25:55 - 25:56
    Alright
  • 25:56 - 26:00
    Switching gears entirely, let's talk about command-line arguments
  • 26:00 - 26:04
    So command-line tools. There are a lot of them
  • 26:04 - 26:08
    And most of them take different arguments because they do different things
  • 26:08 - 26:13
    We've talked about looking at man pages for commands and that will tell you how this particular command works
  • 26:13 - 26:17
    What kind of flags and options you might give to it
  • 26:17 - 26:19
    And what it actually does when you invoke it
  • 26:20 - 26:23
    But there are some common themes that are useful to know about
  • 26:23 - 26:29
    Either in arguments that many programs take, or just concepts the many of them apply
  • 26:30 - 26:35
    The first of these we already mentioned a little bit in the lecture on command-line environments
  • 26:35 - 26:41
    Which is the "--help" flag. Very often you can pass this to a program and instead of running,
  • 26:41 - 26:47
    It will just print out information about how you can run this program, often in a very short, condensed way
  • 26:48 - 26:55
    A similar one is the "--version" flag, which just prints the version of the software you're using
  • 26:55 - 26:58
    This can be really handy if you're doing something like filing a bug report,
  • 26:58 - 27:00
    Which Anish is going to talk a little bit about later
  • 27:00 - 27:04
    And you want to report what version you're running on in case the bug has been fixed since
  • 27:05 - 27:10
    Often you can also do "-V" and that means the same as version. But again, check the man page
  • 27:12 - 27:17
    There's also "--verbose", or "-v" often
  • 27:17 - 27:21
    Which is a flag that lets you increase the output of the program
  • 27:21 - 27:26
    It makes the program print more about what it is doing. And very often you can repeat this flag
  • 27:26 - 27:31
    So you can do like "-vvvvv" in order to get more information from that tool
  • 27:31 - 27:35
    And this can be especially useful if you're trying to debug a problem
  • 27:35 - 27:39
    If you're like running "rsync" and you want to know why did it decide to copy this file?
  • 27:39 - 27:44
    Or why did it decide not to copy this file? That kind of debug output can be useful
  • 27:44 - 27:48
    And often there's a sort of an inverse flag called "quiet" or "silent"
  • 27:48 - 27:53
    Which means that the tool will not print anything unless it was like an error
  • 27:53 - 27:55
    Anything else, it will stay quiet about
  • 27:56 - 27:59
    Many tools, especially those that do destructive actions
  • 27:59 - 28:03
    Or some kind of action that you cannot undo
  • 28:04 - 28:06
    Provide what's known as a "dry run flag"
  • 28:07 - 28:10
    Exactly how this is represented in the command line varies from tool to tool
  • 28:10 - 28:17
    But essentially what this dry run mode will do is it will run the tool, but it will not actually make any changes
  • 28:17 - 28:23
    Instead it will just inform you of what it would have done if you hadn't run it with dry run
  • 28:24 - 28:30
    Many of these tools also have an interactive mode. So for example, th "rm" and "mv" tools both do
  • 28:31 - 28:33
    Often just "-i", although not always
  • 28:33 - 28:36
    When you run a tool in interactive mode
  • 28:36 - 28:40
    It will usually prompt you whenever it's about to do an action that you can't undo
  • 28:40 - 28:44
    And it will sort of prompt you for a confirmation that it should actually go ahead
  • 28:47 - 28:50
    When we're talking about destructive tools
  • 28:50 - 28:53
    Many of them are non-recursive by default
  • 28:53 - 28:57
    If you try to remove a directory or you try to operate on a full directory
  • 28:57 - 29:00
    They will not continue into the files inside of that directory
  • 29:00 - 29:05
    The reason being you might accidentally like, remove your entire hard drive and that seems bad
  • 29:06 - 29:08
    Therefore for many of these tools, they have a "recurse" flag
  • 29:08 - 29:11
    Often "-r", but again not always
  • 29:11 - 29:17
    Which lets them traverse down into the tree to go deeper, but you need to opt-in to this behavior
  • 29:17 - 29:22
    So this is for example, the case for "rm". This is also the case for "cp"
  • 29:24 - 29:28
    In many tools, when they ask you to give a file name or a path
  • 29:28 - 29:31
    And we talked about this a little bit in the data wrangling lecture
  • 29:31 - 29:35
    Instead of giving a file name, you can often just give a dash
  • 29:35 - 29:40
    Just a single "-", and what that means is standard input or standard output
  • 29:40 - 29:43
    Depending on whether that argument is an input file or an output file
  • 29:43 - 29:49
    This is handy to know about if you're trying to construct those kinds of data wrangling pipelines that we've talked about before
  • 29:49 - 29:55
    Many tools will also default to using standard in or standard out if you don't give any file name at all
  • 29:57 - 30:03
    Sometimes you want to pass something that looks like a flag or an option to a command
  • 30:04 - 30:07
    But you don't actually want it to be interpreted as a flag or an option
  • 30:07 - 30:15
    Consider for example, if you wanted to remove a file called "-i", what would you do?
  • 30:15 - 30:18
    Right, if you write the following command...
  • 30:19 - 30:22
    "rm -i"
  • 30:22 - 30:29
    Well, "-i" is a flag to "rm", so "rm" would, when you run this command say
  • 30:29 - 30:33
    Tell me what file to remove, you haven't given me a file
  • 30:33 - 30:36
    And it's because it interprets this as a flag
  • 30:36 - 30:38
    Similarly, if you do something like...
  • 30:39 - 30:49
    "ssh some machine, some command, and let's say, dash r"
  • 30:50 - 30:56
    So this is saying - run command "foo" on this machine over SSH, and I wanna pass "-r" to "foo"
  • 30:57 - 31:02
    Well, the way that both of these are gonna get interpreted is that these are flags
  • 31:03 - 31:07
    Or in this case, this is a flag. But to this command
  • 31:08 - 31:11
    Which is probably not what you expected
  • 31:11 - 31:14
    Actually in the case of SSH, it has some weird special behavior for some of these
  • 31:15 - 31:18
    But often if you want something to not be interpreted as a flag
  • 31:18 - 31:22
    There's a very simple way to opt-out of that, and that is using double dash
  • 31:23 - 31:26
    If you use double dash, what you tell the command
  • 31:26 - 31:30
    Is that verything following this, you should not interpret
  • 31:31 - 31:36
    So it will not be considered a flag or an option. In the case of "rm" you can do this
  • 31:37 - 31:40
    And now "rm" you will see that the first argument is a "--"
  • 31:41 - 31:45
    And then it will keep reading arguments, but it will not interpret them as flags
  • 31:45 - 31:51
    So when it gets the "-i", it will not interpret it as the dash i flag, but just as an argument dash i
  • 31:52 - 31:59
    Similarly, for SSH you can do this to indicate that these are both positional arguments
  • 31:59 - 32:04
    They are not flags or options and you should not interpret things that start with a dash
  • 32:09 - 32:13
    (student) But if you do like "--version", it's not gonna trigger that?
  • 32:13 - 32:18
    (Jon) No, so this is a " -- ", with a space on both sides
  • 32:20 - 32:25
    Any questions about any of this sort of command line conventions business?
  • 32:29 - 32:31
    Alright then let's talk about window managers
  • 32:32 - 32:35
    So most of you are used to some kind of drag-and-drop window manager
  • 32:36 - 32:43
    If you're running Windows, or Mac OS, or Ubuntu - what comes with the machine is like, there are windows and
  • 32:43 - 32:47
    They overlap partially on screen and you can like drag-and-drop and move them around and resize them and stuff
  • 32:48 - 32:51
    And that works fine
  • 32:51 - 32:56
    But it is not the only way to manage windows on your computer it turns out
  • 32:57 - 33:02
    So what you are used to is something called a floating window manager, but not all window managers are floating
  • 33:03 - 33:10
    Often you can opt-in to other types of window managers that have different behavior for how they arrange your desktop
  • 33:11 - 33:14
    A common alternative is a tiling window manager
  • 33:14 - 33:18
    So in a tiling window manager, rather than having floating windows,
  • 33:18 - 33:24
    Everything is set up into a tiled layout. When you start a program, its window is maximized
  • 33:24 - 33:28
    If you start another program, the original window shrinks in size
  • 33:28 - 33:32
    And then the new window takes up some subset of the total desktop space
  • 33:32 - 33:37
    At no time is your desktop background visible unless you have no programs open
  • 33:37 - 33:42
    All of the programs you have open on any given desktop are going to share that space
  • 33:43 - 33:48
    This looks a little bit like tmux panes, like we talked about earlier, where you can sort of split them in various directions
  • 33:49 - 33:55
    And one of the reasons why this is handy is it means you basically never need to go to your mouse
  • 33:55 - 33:59
    In order to move between windows, there are keyboard shortcuts to move to different windows
  • 33:59 - 34:03
    There are keyboard shortcuts for resizing the windows or swapping them around on screen
  • 34:03 - 34:07
    And this turns out to be a pretty efficient way to manage windows in your computer
  • 34:10 - 34:15
    Well, I won't go into too much of detail of what kind of window managers you might use
  • 34:15 - 34:19
    Just know that these exist out there and they're worth giving a look. They can be a lot more efficient to work with
  • 34:20 - 34:23
    Questions about window managers?
  • 34:24 - 34:28
    All right, VPNs. Totally related to the previous topic
  • 34:28 - 34:32
    So VPNs are like all the rage these days and this makes me really sad
  • 34:33 - 34:36
    It's not clear that VPNs are all the rage for any good reason
  • 34:36 - 34:40
    Because you should be aware of what a VPN does and does not get you
  • 34:40 - 34:48
    A VPN, in the best case, is really just a way for you to change your internet service provider
  • 34:48 - 34:54
    It's a way for you to make traffic on the Internet seem like it's coming from somewhere else than where you actually are
  • 34:57 - 35:01
    While that might seem attractive for certain purposes,
  • 35:01 - 35:04
    It's a little unclear what it buys you in terms of security
  • 35:04 - 35:07
    Because all you're really doing is shifting who you are trusting
  • 35:08 - 35:11
    Rather than trusting who is providing your current internet service,
  • 35:11 - 35:16
    You're trusting that whatever business is giving you that VPN service...
  • 35:16 - 35:20
    You're trusting that they, first of all, have set up this VPN business correctly,
  • 35:20 - 35:24
    But also that they are not tracking what you are doing
  • 35:24 - 35:29
    And it's not clear whether that change of trust is actually worth it
  • 35:29 - 35:34
    If you're sitting at some like dodgy public Wi-Fi network then maybe
  • 35:34 - 35:36
    But if you're sitting at MIT, it's not clear
  • 35:36 - 35:41
    Do you trust your VPN provider more than you trust MIT's IS&T?
  • 35:41 - 35:44
    Or maybe you do, but that is a decision that you need to make
  • 35:44 - 35:47
    About what you trust, who you trust and why?
  • 35:48 - 35:52
    You should also know that much of your traffic,
  • 35:52 - 35:57
    Especially the stuff that's on a sensitive nature on the Internet, is already encrypted
  • 35:57 - 36:04
    Whether that's sort of HTTPS or other protocols that use something like TLS, a lot of the sensitive data is already
  • 36:04 - 36:10
    Sent over encrypted channels and it doesn't really matter who your network provider is if you're on a dodgy Wi-Fi network
  • 36:10 - 36:15
    The stuff that matters is probably encrypted anyway. Might not be, but if it's not
  • 36:15 - 36:21
    Then your VPN provider can also see it in plain text just as much as whoever's hosting this dodgy Wi-Fi network
  • 36:21 - 36:26
    And notice that I said "in the best case above"
  • 36:26 - 36:32
    There are VPN providers who have been shown to be malicious, that do logging of all your traffic,
  • 36:32 - 36:38
    That sell that traffic to third parties. There are VPN providers that have forgotten to enable encryption on the VPN
  • 36:38 - 36:42
    All of these are real problems
  • 36:42 - 36:49
    And so you should think very carefully about whether a VPN actually serves any good purpose for you
  • 36:49 - 36:53
    Questions about VPNs? Yes?
  • 36:53 - 36:56
    (student) So I have a question about public Wi-Fi networks, because
  • 36:56 - 37:03
    The traffic from your computer to the router isn't encrypted between the computer and the router, right?
  • 37:03 - 37:07
    Except for what normally is via HTTPS and [unintelligible]
  • 37:07 - 37:14
    So then doesn't that mean that people could sniff out what domains I'm going to via the DNS request?
  • 37:14 - 37:16
    (Jon) So, it's a very good question
  • 37:16 - 37:22
    If you're on a public Wi-Fi network, then the traffic between you and the wireless access point is not encrypted
  • 37:22 - 37:27
    At least it's not encrypted sort of on the outer layer, but it might be encrypted in like HTTPS, for example
  • 37:27 - 37:34
    And it is totally true the people observing that Wi-Fi network will be able to see anything that is not encrypted
  • 37:34 - 37:40
    But the solution to that is to encrypt all your traffic, rather than necessarily going through a VPN
  • 37:40 - 37:47
    So one way to do this for example is to use DNS over TLS or DNS over HTTPS, which gives you
  • 37:47 - 37:52
    A way to actually encrypt even information that might otherwise leak in plain text
  • 37:52 - 37:56
    Rather than try to sort of trust some provider to do that for you
  • 37:56 - 38:02
    Now that said, in some cases you might have a trusted institution that provides a VPN network for you
  • 38:02 - 38:09
    So for example, MIT provides a VPN network for all MIT students and staff that you can sign up to use
  • 38:09 - 38:14
    And in that case you probably trust MIT more than the other networks you might be on
  • 38:14 - 38:18
    So it might be worth it, but it's something for you to think about
  • 38:18 - 38:22
    (student) When you say you could encrypt it with, what was it, DNS, how would you do that?
  • 38:24 - 38:29
    (Jon) So, DNS is the way that people turn domain names,
  • 38:29 - 38:32
    Or your computer turns domain names into IP addresses to know what computer to connect to
  • 38:32 - 38:37
    And that protocol by default is in plain text. There's nothing encrypted about it
  • 38:37 - 38:41
    There are various ways to encrypt your DNS traffic
  • 38:41 - 38:44
    Some of them are standardized and some of them are not
  • 38:44 - 38:49
    I won't go into the exact mechanics here, but you should google it and look at some of the ways
  • 38:50 - 38:53
    Okay. The last thing I want to talk about is Markdown
  • 38:53 - 38:59
    So there is a high chance that some of you are going to write text over the remaining part of your life
  • 38:59 - 39:03
    And you will want to mark up that text in various simple ways
  • 39:03 - 39:09
    And one thing you could do is start up Word or use LaTeX or something like that to mark up your documents
  • 39:09 - 39:11
    But that is a pretty heavy-handed approach
  • 39:11 - 39:13
    Instead it would be nice if we could just sort of
  • 39:13 - 39:16
    Write things the way we feel like they should be
  • 39:16 - 39:21
    I don't know how to describe it in a better way but sort of the natural way where if you want something,
  • 39:21 - 39:25
    If you want to put emphasis on a word you just put like stars around it or something, and then it just works
  • 39:25 - 39:32
    Markdown is essentially that. It is a way to try to encode the way that we often write text somewhat naturally
  • 39:32 - 39:37
    Into a markup language that lets you write things like bold text, links, lists, that sort of stuff
  • 39:38 - 39:42
    In fact, all of the lecture notes for this class have been written using Markdown
  • 39:42 - 39:46
    And Markdown is really very straightforward. The basic rules are in the notes
  • 39:46 - 39:54
    But the basic things you need to know is, in Markdown if you put stars
  • 39:54 - 40:00
    Around a word, that word is emphasized. Or some sequence of words. If you put double stars
  • 40:01 - 40:05
    That word is emphasized strongly, also known as bold
  • 40:05 - 40:11
    There are various other things you could do, like if you put a dash before a line it is now a list
  • 40:11 - 40:14
    And there's one list item and you can amend list items
  • 40:14 - 40:19
    If you put "1." in front, or some other number, it becomes a numbered list
  • 40:19 - 40:25
    If you put a pound sign in front of something it becomes a header, like some kind of title header
  • 40:25 - 40:30
    If you put multiple of them, they become subheadings and you can keep adding more to these
  • 40:31 - 40:38
    If you want to write code you can put a single backtick, followed by some code, followed by a backtick
  • 40:38 - 40:41
    And now that is rendered in Monospaced Font
  • 40:41 - 40:47
    If you want multiple lines of code, you do a triple backtick, and then code,
  • 40:47 - 40:51
    And then maybe some more code and then triple backtick
  • 40:51 - 40:54
    And in many cases like if you're on GitHub for example,
  • 40:54 - 40:58
    You can even type the name of a language up here after the backticks, without a space
  • 40:58 - 41:02
    And it will be syntax highlighted in the language of your choice
  • 41:02 - 41:08
    This is a really handy thing that is supported in so many websites nowadays you might not even realize
  • 41:08 - 41:11
    Like in Facebook Messenger you can use many of these
  • 41:12 - 41:14
    They don't actually officially say they support Markdown anywhere
  • 41:14 - 41:18
    But many of these things just like sort of happen to work and it's worth learning
  • 41:18 - 41:23
    At least the basics and just start using them. You can do links and stuff as well, but that's already in the notes
  • 41:24 - 41:26
    Any questions about Markdown?
  • 41:28 - 41:32
    Right, Anish, you're up
  • 41:35 - 41:37
    (Anish) Is my microphone working?
  • 41:38 - 41:41
    Is this working? Can you guys hear me in the back?
  • 41:42 - 41:46
    The light's green. Oh, I think I can hear it. Okay, great
  • 41:48 - 41:54
    So, continuing with our theme of random topics that are all unrelated to the previous topics we've been talking about,
  • 41:54 - 41:57
    The next thing we're going to talk about is a program called "Hammerspoon"
  • 41:57 - 42:00
    Which is a tool for doing desktop automation on Mac OS
  • 42:01 - 42:05
    And I think there's similar tools for Windows and Linux, a lot of the ideas can carry over
  • 42:05 - 42:09
    You can google it if you want to figure out how to do these things on other platforms
  • 42:09 - 42:13
    But basically Hammerspoon is a program that lets you write Lua scripts, scripts in a programming language
  • 42:13 - 42:16
    That interact with various operating system functionality
  • 42:16 - 42:20
    So you can write code that interacts with the keyboard and mouse and connects that to window management,
  • 42:20 - 42:26
    To display management, the file system, battery and power management, Wi-Fi... All sorts of stuff
  • 42:26 - 42:31
    Like basically all the things that your operating system manages, this tool lets you hook into those things
  • 42:31 - 42:34
    And so it can let you do all sorts of neat things by writing just a couple lines of code
  • 42:34 - 42:40
    Just some examples of cool things you can do with this tool are - you can bind hotkeys to move windows to
  • 42:40 - 42:45
    Specific locations. So a demonstration of this is here. I have this window open. I press, in my particular setup,
  • 42:45 - 42:50
    "Option+Command+Right" and this window moves to the right. "Option+Command+Left", this window moves to the left
  • 42:50 - 42:52
    And I have a couple other shortcuts for moving things to various places
  • 42:52 - 42:57
    And so I can kind of have an effect similar to tiling window managers that Jon was talking about earlier
  • 42:58 - 43:03
    I can move windows to different parts of my screen to set things up in a particular way rather than have to use the mouse
  • 43:03 - 43:08
    To position things where I want them to be and then like click and drag to resize windows to the right shape
  • 43:08 - 43:10
    Just a keyboard shortcut can do the trick
  • 43:10 - 43:15
    But this tool is not limited to just moving windows around and binding that to particularly keyboard shortcuts
  • 43:15 - 43:19
    You can do other things like create a menu bar button with a bunch of different options
  • 43:19 - 43:23
    And you can bind those different options to do different things. So in my particular case
  • 43:23 - 43:28
    I've created this little menu and then I have a bunch of different things that I do reasonably frequently and clicking on these things
  • 43:29 - 43:33
    Invokes a particular Lua function that I've written that interacts with this library. So for example
  • 43:34 - 43:39
    Here, this "Rescue windows" thing is a particular thing where I often work with multiple displays
  • 43:39 - 43:45
    And sometimes my operating system gets confused and I have some window that ends up off of my display and
  • 43:45 - 43:47
    How do I how do I get this thing back?
  • 43:48 - 43:50
    Well, that's what this... Whoops, not that
  • 43:52 - 43:57
    That's what this "Rescue windows" thing does. It brings windows that are off the screen back onto the screen
  • 43:58 - 44:02
    Another neat thing I have setup here is I have particular layouts that I've named
  • 44:02 - 44:04
    So like a dorm, and a Lab and a Laptop layout
  • 44:04 - 44:05
    So for example in my Lab
  • 44:05 - 44:09
    I have this screen and I have another screen and have another screen besides that in a different orientation
  • 44:09 - 44:12
    And I have this particular setup that I want where I want
  • 44:12 - 44:15
    Maybe my terminal full screen on here, and my chat program over here and
  • 44:15 - 44:18
    This screen split up into five segments with different programs in different places
  • 44:19 - 44:26
    Here I can, when I show up to Lab I can just go here and click "Layout Lab" and it will invoke some code
  • 44:27 - 44:32
    Which is not all that complicated like 10 lines of code describes a particular layout
  • 44:32 - 44:36
    And it will instantiate that layout and put all the things where they need to go
  • 44:36 - 44:42
    I could even in theory automate some of these things where my computer could figure out like I plug in a display and my computer knows
  • 44:42 - 44:46
    Oh, this is the display that you have in your lab. Let me automatically instantiate this layout for you
  • 44:46 - 44:51
    That's another thing you can do with Hammerspoon. And also other wacky things you can do like you can do things like
  • 44:52 - 44:55
    It can detect your Wi-Fi network that you're on so it knows kind of where you are
  • 44:55 - 45:00
    Maybe I have a different Wi-Fi network name at home versus in lab and I can do things like when I show up to lab
  • 45:00 - 45:04
    Automatically mute my speakers. So I don't have like embarrassing music play out loud in my lab
  • 45:05 - 45:07
    Another kind of cool example is
  • 45:08 - 45:09
    So I have a Mac
  • 45:09 - 45:12
    It has a fancy power supply and a lot of my friends have
  • 45:12 - 45:15
    Computers that look the same as this and their power supply bricks look the same as mine and
  • 45:16 - 45:19
    Sometimes I use their power brick because I forgot mine at home or something
  • 45:19 - 45:22
    This tool can actually with like three or four lines of code
  • 45:22 - 45:27
    Do neat things like show you a warning like it'll pop up a warning if you've accidentally taken your friend's power supply and plugged it
  • 45:27 - 45:29
    Into your computer instead of using your own
  • 45:30 - 45:35
    So at a high level this tool lets you run arbitrary Lua code and do things like bind it to menu buttons or key presses and
  • 45:35 - 45:39
    It interacts with a large part of the operating system in order to do all sorts of cool stuff
  • 45:40 - 45:42
    So that is Hammerspoon, any questions about that?
  • 45:44 - 45:47
    Cool. Moving on to the next topic
  • 45:47 - 45:51
    Completely unrelated to the previous one, it's booting and live USBs
  • 45:52 - 45:55
    So the operating system on your computer, Windows or Mac OS
  • 45:56 - 46:01
    or whatever you're used to is not exactly the first thing that runs on your machine when it turns on. There's something else that
  • 46:01 - 46:04
    happens in the boot process before your operating system is loaded and
  • 46:05 - 46:08
    There's some interesting stuff that you can do there. So you might have seen when you turn on your computer
  • 46:08 - 46:13
    It says something like press F9 to configure the BIOS or press F12 to enter the boot menu
  • 46:14 - 46:18
    The particular key sequences may depend on your machine and specific configuration
  • 46:18 - 46:23
    But this is a general pattern and you can configure all sorts of interesting Hardware related stuff here
  • 46:23 - 46:24
    So it's worth checking out
  • 46:24 - 46:29
    And another thing you can do in this boot menu is you can have your computer start off from an alternate boot device
  • 46:29 - 46:34
    so by default like my laptop here has a solid-state drive and it boots Mac OS when it turns on but I can also
  • 46:34 - 46:40
    say plug in a USB flash drive that has an operating system installed on the flash drive and then at boot tell my computer to
  • 46:40 - 46:45
    Boot from that flash drive instead of the built-in solid-state disk, and this is useful
  • 46:45 - 46:45
    for example
  • 46:45 - 46:47
    If I've broken my operating system
  • 46:47 - 46:52
    Install and I want to do something like get the data off my computer or maybe want to fix the operating system
  • 46:52 - 46:55
    Like maybe there's some critical files somewhere that I've deleted or I forgot my password
  • 46:55 - 46:59
    I need to go like tweak some files in order to reset it booting from a live USB
  • 47:00 - 47:04
    Booting from the separate operating system that's installed on a flash drive can let me do that like boot up my operating system
  • 47:05 - 47:07
    Mount the hard disk that's on my current machine
  • 47:07 - 47:10
    I'm working on and then go make some tweaks or copy data off of that
  • 47:10 - 47:16
    And so live USBs are really useful and in the lecture notes, we've linked to a tool that can help you create them really easily
  • 47:17 - 47:20
    Any questions about the boot process or live USBs?
  • 47:22 - 47:29
    All right, next topic is virtual machines, Vagrant, Docker, the cloud and OpenStack
  • 47:29 - 47:32
    I think last year we had an entire lecture on this topic this year
  • 47:32 - 47:34
    We're going to condense it into like one minute
  • 47:34 - 47:41
    So at a high level virtual machines and similar tools like containers let you emulate a whole computer system within your current machine
  • 47:41 - 47:44
    so like I'm running Mac OS here, but within my Mac OS
  • 47:45 - 47:46
    environment I can
  • 47:46 - 47:50
    Simulate a machine that's running say Ubuntu or some other operating system
  • 47:50 - 47:55
    And this is a nice way of creating an isolated environment for testing or for development or for exploration
  • 47:56 - 48:01
    For example doing things like running potentially malicious code that should be isolated from my current environment. I
  • 48:01 - 48:07
    Think the most common use case for programmers is to use virtual machines are containers to create development environments
  • 48:07 - 48:12
    So I'm using Mac OS and I have some of services and stuff and libraries installed in my current machine
  • 48:12 - 48:13
    But I might want for example
  • 48:13 - 48:18
    I'm working on some web programming project and I want it to run on an
  • 48:19 - 48:20
    Debian machine and I need
  • 48:20 - 48:24
    Postgres, like a database server installed rather than install that all on my Mac OS machine
  • 48:24 - 48:29
    I can instantiate this new machine just for the development purposes
  • 48:30 - 48:35
    Now virtual machines, like that's a general concept. There are a bunch of programs that let you
  • 48:35 - 48:38
    that are called virtual machine hypervisors that
  • 48:38 - 48:45
    Support this functionality on your machine and then there are tools that let you script these hypervisors in order to specify machine
  • 48:45 - 48:51
    Configurations like operating system and like what packages you want installed and what services you want installed in plain text
  • 48:51 - 48:57
    And so this is an example on the screen right here. And this is done using a system called Vagrant.
  • 48:58 - 49:01
    It's linked in the lecture notes. You can look into this if you're curious.
  • 49:01 - 49:05
    So basically and the short plain text file I can specify okay. I want a machine that's running Debian
  • 49:05 - 49:09
    It should have "postgres" and Redis and Python and stuff installed on it.
  • 49:09 - 49:11
    And then, once I have this configuration,
  • 49:11 - 49:17
    I can just type in "vagrant up", and what it does is, it reads this file and instantiates a new machine based on this
  • 49:17 - 49:23
    configuration. And then, after I've done that I can do "vagrant ssh" to SSH into this virtual machine.
  • 49:23 - 49:26
    So it's not a remote machine running on some other piece of hardware somewhere,
  • 49:26 - 49:31
    It's just simulated on my own machine, but now here I have an Ubuntu box like I do now, let's be really stashe
  • 49:31 - 49:35
    It's like or sorry not a bunch of debian here with all the things
  • 49:35 - 49:38
    I want installed in here and I can do my development inside this isolated environment,
  • 49:38 - 49:42
    and not, kind of, install all this junk on my MacOS machine.
  • 49:43 - 49:50
    Now so that's vagrant there's similar tools like docker that are conceptually similar but use containers instead of virtual machines
  • 49:50 - 49:53
    It's a distinction that we're not going to talk about in too much detail right now
  • 49:54 - 49:56
    And so you can run VMs on your own computer
  • 49:56 - 49:59
    but you can also rent virtual machines on the cloud and so
  • 49:59 - 50:03
    It's a nice way to get instant access to like one example is you might want a computer
  • 50:03 - 50:08
    That's always on always connected to the internet and has a public IP address. Like maybe you want to run a web server
  • 50:08 - 50:12
    That's always available or you want to run some other service like say a slack bot or something like that
  • 50:12 - 50:14
    Well a virtual machine
  • 50:14 - 50:19
    rented on the cloud is one nice way to get that and these are pretty cheap for like a low capacity machine with a
  • 50:19 - 50:21
    small CP and small amount of disk space and
  • 50:22 - 50:27
    You might want to do is get access to a machine that's really powerful like with a lot of CPU cores or with a lot
  • 50:27 - 50:31
    Of RAM or with a whole bunch of GPUs for some specific purpose like say you're doing deep learning or so
  • 50:31 - 50:33
    You're doing some other sorts of sensitive computation
  • 50:33 - 50:35
    Well, that's another thing you can do with VMs on the cloud
  • 50:35 - 50:41
    And finally, you can get access to many more machines than you have physical access to. Like if I need a thousand machines
  • 50:41 - 50:47
    But only for two minutes to do some very parallel tasks. That's something I can easily do with virtual machines and
  • 50:48 - 50:51
    Popular services for doing this are things like Amazon AWS or Google cloud
  • 50:51 - 50:57
    And if you're a member of MIT CSAIL, you can also get free VMs for research purposes using the CSAIL OpenStack
  • 50:57 - 50:59
    And so this is also linked in the lecture notes
  • 51:00 - 51:03
    So any questions about virtual machines, or Vagrant, Docker, or anything like that?
  • 51:13 - 51:17
    So the question is when I say I'm running Ubuntu, or, actually, in this case, it's Debian
  • 51:18 - 51:22
    when I'm running Ubuntu here, do I have, like, Ubuntu installed on my machine, or
  • 51:23 - 51:28
    What exactly is going on here? So, basically, what Vagrant did for me when I type "vagrant up" is,
  • 51:29 - 51:35
    because I've specified I want Debian here, it downloaded Debian from the internet, like, set up a disk image for this new machine,
  • 51:36 - 51:39
    installed Debian into that disk image, then went to install these programs
  • 51:39 - 51:44
    So, like, yes, this is on my computer. But, all of this is just in a particular file that's a disk image.
  • 51:44 - 51:48
    And then, I'm emulating a machine that is basically completely isolated from my current machine.
  • 51:48 - 51:55
    This is being run as a process on my current machine. Does that answer the question? Any other questions about VMs?
  • 51:57 - 51:58
    Great.
  • 51:58 - 52:00
    Next topic is also going to be a quick mention -
  • 52:00 - 52:02
    So,
  • 52:02 - 52:05
    a lot of you are programmers, and you're used to writing programs
  • 52:05 - 52:08
    in a tool like Vim, or some other editor that you're comfortable with.
  • 52:08 - 52:13
    Another thing that can be really neat to use for particular tasks, is something called a notebook programming environment.
  • 52:13 - 52:17
    And this is a more interactive way of writing programs. Here on the screen, I have a demo.
  • 52:17 - 52:23
    This is something called Jupiter notebook and it can be used for writing Python programs. I think they also support some other languages.
  • 52:24 - 52:26
    And, basically, this is a nice way of doing interactive programming.
  • 52:26 - 52:30
    So, normally, you're used to writing a big program in a file, or a collection of files,
  • 52:30 - 52:35
    and once you're done writing it, you can just run the whole program. But, this lets you be a little bit more flexible and
  • 52:36 - 52:40
    run little snippets of code at a time. Like, for example, I can break my program into these little pieces.
  • 52:40 - 52:46
    It's just some random code I wrote. And, I can say, "execute this cell", and I press a particular key combination to execute the cell.
  • 52:46 - 52:51
    But then, I can go back, and tweak my program a little bit. Like, say I want to have this be lowercase instead.
  • 52:51 - 52:55
    Then, I can execute this cell, and then go and evaluate this thing, and
  • 52:55 - 53:00
    this way I can, kind of, run little snippets of code, within a Python environment.
  • 53:01 - 53:06
    And, it's a nice way of building up programs, piece by piece, rather than having to write everything at once.
  • 53:06 - 53:11
    This is really useful for particular research purposes, like I think a lot of people use these for doing machine learning work, for example.
  • 53:13 - 53:18
    Any questions about the idea of notebook programming environments? They're worth checking out.
  • 53:24 - 53:28
    Oh, so the question is, "This looks like it's online, is there an offline version of Jupiter notebooks?"
  • 53:28 - 53:33
    So, actually, this is the thing that runs in the browser, but it's running locally...
  • 53:33 - 53:35
    So, I don't know if you can see it on the screen, because it's kind of small, but up here
  • 53:35 - 53:37
    it says, "localhost:8888".
  • 53:38 - 53:44
    Here, I have running on my own local machine, a Jupiter notebook. And, they've just built it
  • 53:44 - 53:46
    so it runs within the web browser.
  • 53:47 - 53:49
    That being said, there are also online
  • 53:49 - 53:55
    Jupiter notebooks that you can use, where the Python kernel is actually running on some remote machine. You might want to do this
  • 53:55 - 53:56
    for example, like on my laptop,
  • 53:56 - 54:00
    I don't have a fancy GPU, but in my room, I have a machine with a fancy GPU. And so, when I'm doing machine learning
  • 54:00 - 54:07
    work, I often SSH into that machine, run a Jupiter notebook on there, and then open up the interface, in my local web browser,
  • 54:07 - 54:10
    so I have access to that powerful GPU running on my different machine.
  • 54:12 - 54:14
    Any other questions?
  • 54:16 - 54:18
    Great.
  • 54:18 - 54:20
    The final thing we're going to talk about today is
  • 54:20 - 54:24
    Github. So, we touched on this a little bit during the version control lecture.
  • 54:24 - 54:28
    But, Github is one of the most popular platforms for open-source software development.
  • 54:28 - 54:35
    It hosts source code. It hosts git repositories. But, they also have other tools for managing a project.
  • 54:36 - 54:42
    And, like, a lot of the tools we've talked about in this class are hosted on Github. For example,
  • 54:42 - 54:46
    like, Hammerspoon, the thing we just talked about, is developed on Github
  • 54:46 - 54:48
    It's really easy to get started
  • 54:48 - 54:54
    contributing to open-source projects on Github to help improve the tools that you use every day.
  • 54:54 - 54:58
    There are two primary ways you can contribute to projects on Github.
  • 54:59 - 55:06
    Let's open up some repository. We can actually go to the Github repository for the class website.
  • 55:06 - 55:08
    So, this is an open-source software project.
  • 55:09 - 55:11
    And...
  • 55:11 - 55:15
    Let's zoom in a little bit. So the two ways you can contribute to projects on Github -
  • 55:15 - 55:17
    The two main ways are through issues and pull requests
  • 55:17 - 55:24
    One thing that's actually really helpful to developers, and also pretty lightweight and easy for users to do, is to report issues with a
  • 55:24 - 55:27
    software project. Like, say you're using somebody's program and you encounter some bug...
  • 55:28 - 55:32
    Writing a high quality issue is actually super helpful to developers and hopefully doesn't take you too much time.
  • 55:32 - 55:38
    And so, you can go to here, like find the project on GitHub, go to the issues page, and click on new issue, and then
  • 55:38 - 55:42
    write some high quality bug report. And then, hopefully the developer will respond and fix the issue for you.
  • 55:42 - 55:43
    So, for example, for this class,
  • 55:43 - 55:49
    like, one of the students in this class pointed out an issue with our lecture notes, and after she pointed it out,
  • 55:49 - 55:55
    I said, okay, like, that looks like a reasonable thing. Let's fix it. And in this particular case, instead of fixing it myself,
  • 55:55 - 56:00
    I actually asked this person, "Do they just want to fix it for me?" And so, that leads into the other thing
  • 56:00 - 56:06
    I want to talk about: issues and pull requests. So, pull requests are the second way to contribute to projects on Github. And,
  • 56:07 - 56:10
    this involves actually contributing code back to the project. And
  • 56:11 - 56:17
    so if we look at the pull request for this particular project, you'll see that a bunch of people have submitted code changes.
  • 56:18 - 56:19
    And,
  • 56:19 - 56:24
    the process for doing so - so this is showing the difference, the patch, that this person submitted.
  • 56:25 - 56:30
    Basically, the process for creating pull requests is a little bit more involved than submitting issues. Like you're not just submitting text:
  • 56:30 - 56:32
    you're actually going to modify their source code.
  • 56:32 - 56:36
    And so, we've linked to some guides that explain the process in a little bit more detail.
  • 56:36 - 56:42
    But, at a high level, what you do is, you take the repository on Github, "fork" it, and then download it locally,
  • 56:42 - 56:43
    so now have your own, local copy.
  • 56:43 - 56:48
    Then, you can go and work on it, do some development work, and fix a bug or add a feature, and then, eventually, you
  • 56:48 - 56:52
    send what's called a "pull request" back to the original developer. So, you say, 'Here. I've made some changes.
  • 56:52 - 56:55
    Can you please incorporate them back into the original project?'
  • 56:55 - 57:00
    And, after that point, what usually happens with these projects, is that the maintainer will go back and forth with you, giving you feedback on
  • 57:00 - 57:06
    the changes you've proposed. And, eventually, once everybody's happy, they will "merge" in your changes, and they'll be available to everybody who uses the project.
  • 57:08 - 57:14
    So, that is how you can contribute to projects on GitHub and make software better for everybody. And, so any questions about GitHub?
  • 57:19 - 57:24
    Cool, okay. So, that is it for the topics for today. Any questions about the lecture overall?
  • 57:26 - 57:28
    Great, okay, so before -
  • 57:28 - 57:33
    before we finish, a quick description about tomorrow's lecture: so, today was all the topics we thought are interesting,
  • 57:33 - 57:34
    we should talk about,
  • 57:34 - 57:39
    tomorrow's lecture is gonna be about all the topics you think are interesting and that we should talk about. So, tomorrow is going to be
  • 57:39 - 57:41
    a Q&A lecture. And, after today,
  • 57:41 - 57:43
    uh, after the lecture, we'll submit,
  • 57:43 - 57:48
    we'll email out a link where you can submit questions for us to answer. And so, please go and fill that out,
  • 57:48 - 57:50
    otherwise, we won't have too much to talk about tomorrow.
  • 57:51 - 57:54
    Great, so hopefully, see you tomorrow in our Q&A lecture.
Title:
Lecture 10: Potpourri (2020)
Description:

more » « less
Duration:
57:55

English subtitles

Revisions