JUNIOR

ACADEMY

8/20/2016

demo from the bossman

window managers

  • A window manager (WM) is software that controls the placement and appearance of windows within a windowing system in a GUI
    • Can be a part of a DE or standalone
  • X clients (applications that run from X servers, which manage GUIs) that control the behavior of windows
  • Types
    • Stacking (floating): WMs that provide traditional desktop metaphor of pieces of paper stacked atop one another
    • Tiling: tile windows with no overlap. Use a lot of key bindings with little to no mouse reliance
    • Dynamic: dynamically switch between tiling or floating

window managers

  • Why use it?
    • More efficient
    • Optimizes window work space
    • Lighter & less resource intensive
    • No need for a mouse
      • Much faster!
    • Customizable
  • Some popular dynamic/tiling window managers
    • awesome
    • bspwm
    • i3

i3wm

  • We'll be using i3 in Academy
    • Dynamic tiling window manager
    • Relatively advanced
    • Multi-monitor support
    • Keybindings and different modes like vim
    • Great documentation
      • https://i3wm.org/docs/userguide.html
  • Installing i3
    • sudo apt install i3
      • i3 package group comes with i3-wm, i3status, and i3lock packages

using i3

  • Keybindings
    • Commands in i3 are invoked with a modifier key, $mod
      • Alt (Mod1) by default
      • Super (Mod4) as an alternative
        • Windows/Command key
    • Check the User's Guide and reference card for defaults
      • https://i3wm.org/docs/refcard.html
  • Containers & workspaces
    • Window management
    • Horizontal & vertical splits
    • Layouts
  • Demonstration -- take notes!

using i3

  • Application launcher
    • i3 uses dmenu as an application launcher
    • $mod+d
    • Launch dmenu and a bar will appear at the top
      • Begin typing your bin command
      • You can scroll through it with left & right arrow key and press Enter to select
      • As the name implies, it launches the application!
    • If you accidentally press it, delete all typed keys until it's selecting " [ " and just press Enter

i3status

  • Generates a status line for i3bar
  • Original/default config file at /etc/i3status.conf
    • Copy to ~/.config/i3status/config OR ~/.i3status.conf
  • Uses modules that you choose (with order)
  • Default configuration
    • IPv6 address for outgoing connections
    • Free disk space on /
    • Is DHCP running?
    • Is a VPN running?
    • Wireless link quality & connection ESSID & IP address
    • Ethernet speed & IP address
    • Battery status, percentage, and remaining time
    • System load (number of processes waiting for CPU)
    • Time & date from local timezone

i3 config

  • ~/.config/i3/config OR ~/.i3/config
    • Depending on distro and directory scheme
    • Original file is at its default location /etc/i3/config
  • 4. Configuring i3 in the User's Guide
  • This is where you can configure i3 to your liking
    • Change the appearance
    • Change i3bar
    • Customize keybindings
      • Have custom commands to run/do things
  • Let's try it out!
    • Change all 8 window management keys from "j k l ;" to the vim keybindings "h j k l"
    • Make a shortcut for i3lock

python

  • Review
  • Loops
  • Functions

review exercises

The squirrels in Palo Alto spend most of the day playing. In particular, they play if the temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100 instead of 90. Given an int temperature and a Boolean is_summer, return True if the squirrels play and False otherwise.

 

def squirrel_play(temp, is_summer):
  

white space

  • White space is the space between statements
  • The white space before statements (indentation) inside of something is important!
  • A block of code is a group of statements, and the white space (tab) separate blocks of code
    • Consistent spacing
  • The 3 dots(. . . instead of >>>) in the interpreter means you're typing in a block of code
  • Blocks placed inside each other require the extra spacing as shown to the right

this is block 1
this is block 1
      this is block 2
      this is block 2
      this is block 2
            this is block 3
            this is block 3
      this is block 2
this is block 1
this is block 1

for loops

  • For loops iterate a limited amount of times through a list with a variable taking on the values in the given list
  • for variable in list:
    • The variable iterates through the list and is assigned the value of the current iteration

  • Like if statements, the for loop is defined with a colon and followed by a block of code that is executed
for x in range(5):
    y = x + 1
    print(x+y)
for s in myList:
    print(s)

for loops

  • The variable that iterates through the list only exists in the for loop, and is purely used for the loop
    • It takes on every value in the list before finishing the loop
  • Example of a for loop: Assuming I earn $35 a week, and I have $0 in my savings account, I can calculate my money earned throughout the weeks for a year!
    • >>> savings = 0
    • >>> for week in range(1, 53):
    • ...     savings = savings + 35
    • ...     print("Week %s = $%s" % (week, savings))

nested loops

  • Try typing this in your interpreter:
    • >>> myList = ['a', 'b', 'c']
    • >>> for u in myList:
    • ...     print(u)
    • ...     for v in myList:
    • ...         print(v)

loop exercise

If you have $100 saved in your bank account, and you obtain 3% interest every year, how much money will you have for each year, up to 10 years?

while we're on loops

  • While loops iterate though the block of code while a condition is met
    • Different from for loops, because it's while condition == true, not iterating through a list
while condition:
    # block of code

while loop example

x = 1
while x < 200:
    x = 2*x
    print(x)

What will this print?

break

  • You can break out of a loop before the condition is met
    • >>> while True:
    • . . .        # tons of code
    • . . .        if someCondition == True:
    • . . .                break
  • Games use while True to keep the game running and refreshing the screen!

another loop exercise

Answer the previous question using a while loop

 

If you don't remember the task:

If you have $100 saved in your bank account, and you obtain 3% interest every year, how much money will you have for each year, up to 10 years?

input()

  • You can take in user-inputted text in the code, and store it in a variable
  • input("text")
    • The user types something in and presses Enter
    • Whatever they typed in is returned by input() as a string
  • >>> name = input("Please enter your name: ")
  • >>> print("Hello, %s!" % name)
  • If they input a number, it is still returned as a string
    • use the int() function to change it to an int
    • >>> age = input("What is your age? ")
    • >>> age = int(age)

functions

  • Functions allow you to write code just once, then reuse that code in your programs multiple times
    • A group of lines of code that should all serve one purpose
  • Functions take in parameters, which is a variable you give it that is only available in the body of the function (the block of code inside of it)
def function(parameter):
    # block of code

example of a function

You define (make) the function like this:

def printName(name):
    print("Hello, %s!" % name)

And call (use) it like this:

printName("John")

Which will print:

Hello, John!

example of a function

Another example, except with return instead of print():

def savings(chores, job, spending):
    return chores + job - spending
    # or return(chores+job-spending)

And call it like this:

print(savings(10, 10, 5))
# OR
money = savings(10, 10, 5)

returning values

When a function returns a value, that value becomes the value of the function

def cow(name):
    return("My cow is named: " + name)

cow("Bob") #nothing will be outputted

myCow = cow("Bob")

cows = [cow("Bob"), cow("Spot"), cow("Hoover")]

functions

  • Return
    • Must be immediately used or saved to a variable, or else the value disappears
    • Useful for holding the value instead of immediately printing it
    • Ends the function
  • General facts
    • Anything with parentheses is a function
      • ex. print("string"), input(), append(), str(), int()
    • You create the parameter when defining the function, and pass it in (give the value) when calling it

scope

  • Not all variables are accessible from all parts of our program.
  • Where a variable is accessible depends on how it is defined.
  • We call the part of a program where a variable is accessible its scope.
  • ​A variable which is defined in the main body of a file is called a global variable.
    • It will be visible throughout the file, and also inside any file which imports that file.
  • A variable which is defined inside a function is local to that function.
    • It is accessible from the point at which it is defined until the end of the function
# This is a global variable
a = 0

if a == 0:
    # This is still a global variable
    b = 1

def my_function(c):
    # this is a local variable
    d = 3
    print(c)
    print(d)

# Now we call the function, passing the value 7
# as the first and only parameter
my_function(7)

# a and b still exist
print(a)
print(b)

# c and d don't exist anymore -- these statements
# will give us name errors!
print(c)
print(d)

function exercise

  • Write a function called practice_function() that takes in a number as a parameter. If the number is less than 50, print the value. If the number is greater than 50 but less than 1000, print a message. If the number is any other value, return the number, then print it. Call the function for three different values: 5, 50, and 200.

 

  • Write a function called describeCity() that accepts the name of a city and its country as parameters. The function should return a simple sentence (for example: "Honolulu is in the USA"). Call your function for three different cities, store them in a list, and print the items in the list separately.

Jr. DevLeague Academy PM 8/20/16

By jtheadland

Jr. DevLeague Academy PM 8/20/16

  • 624