Skip to content

Instantly share code, notes, and snippets.

View andreybutenko's full-sized avatar

Andrey Butenko andreybutenko

View GitHub Profile
@andreybutenko
andreybutenko / my_greeting_function.py
Last active February 4, 2022 01:50
2022-02-03 demos: scopes and list aliasing
# Name: my_greeting_function
# Purpose: Print a message to greet the user
# Inputs: User's name
# Outputs: None
def my_greeting_function(name):
full_greeting = 'Hello ' + name = '!'
print(full_greeting)
my_name = 'Sneha'
my_greeting_function(my_name)

1. run it: basic function

Show students the code sample and ask them to run it individually in the Repl interpreter. After 1-2 minutes ask the group: (1) what did the code do? (2) why?

Code Sample

def my_function():
    print("THIS IS MY FUNCTION!")
library(dplyr)
library(ggplot2)
library(gridExtra)
kBinwidth <- 1
kXBreakBy <- 2
kYBreakBy <- 1
before_data <- c(17,6,4,1,3,18,19,15,13,13,10,8,13,11,2,7,5,17,15,15,2,9,20,18,19)
after_data <- c(17,13,13,5,4,6,9,9,6,14,18,5,9,3,2,12,9,2,4,14,3,13)
@andreybutenko
andreybutenko / bands.R
Created October 23, 2019 05:48
From "Programming Skills for Data Science"
# Install tidyr if necessary:
# install.packages('tidyr')
library(tidyr)
library(dplyr)
bands_wide <- data.frame(
city = c('Seattle', 'Portland', 'Denver', 'Minneapolis'),
greensky_bluegrass = c(40, 40, 20, 30),
trampled_by_turtles = c(30, 20, 40, 100),
billy_strings = c(15, 25, 25, 15),
library(dplyr)
superheroes <- data.frame(
name = c(
'Magneto', 'Storm', 'Mystique', 'Batman',
'Joker', 'Catwoman', 'Hellboy'
),
alignment = c(
'bad', 'good', 'bad', 'good', 'bad', 'bad', 'good'
),
# We are converting Andrey's height from feet to centimeters
feet <- 6
inches <- 2
# Convert 6 feet 2 inches to inches (what's wrong??)
inches_total <- 3 * feet + inches
# Convert inches_total to meters
meters_total <- inches_total / 39.37
console.log(JSON.stringify(
[...document
.querySelectorAll('.experience-section ul li')]
.map(jobElement => ({
role: jobElement.querySelector('h3').innerText,
company: jobElement.querySelector('.pv-entity__secondary-title').innerText,
timeframe: jobElement.querySelector('.pv-entity__date-range span:not(.visually-hidden)').innerText,
description: jobElement.querySelector('.pv-entity__description').innerText.replace('See less', ''),
imageUrl: jobElement.querySelector('img').src
}))
@andreybutenko
andreybutenko / education-viz.R
Created May 20, 2019 19:19
Demo: plotting county-level data with ggplot2
library(ggplot2)
library(dplyr)
library(stringr)
# Okay, the assignment description has a hint that we should use map_data('county')
# if we want to plot county-level data!
# Let's explore what that data looks like...
county_data <- map_data('county')
View(county_data)
@andreybutenko
andreybutenko / demo.R
Created March 8, 2019 21:16
Generating user-defined plots using Shiny inputs with aes_string
library(ggplot2)
# Set up a simple data frame for testing
my_data <- data.frame(
x = 1:20,
foo = 21:40,
bar = 41:60,
baz = 61:80
)
@andreybutenko
andreybutenko / anotherfile.js
Created March 7, 2019 02:16
Vue global store demo
import { globalStore } from './main.js';