Skip to content

Commit 28bba44

Browse files
committed
Render toc-less
1 parent 90547b8 commit 28bba44

32 files changed

+4786
-1834
lines changed

docs/no_toc/01-intro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ This is not a comprehensive list!
8888

8989
- [Phind](https://www.phind.com/) is a AI-powered search engine designed specifically for developers asking technical questions. In addition to answering your coding question, it will provide links to the internet sources used to find the answer.
9090

91-
- [Poe](https://poe.com/) is Quora's platform that gives you access to multiple AI chatbots, including Sage, based on OpenAI's GPT-3.5 architecture; Claude, an AI natural language bot created by [Anthropic](https://www.anthropic.com); and ChatGPT.
91+
- [Poe](https://poe.com/) is Quora's platform that gives you access to multiple AI chatbots, including Sage, based on OpenAI's GPT-3.5 architecture; Claude, an AI natural language bot created by [Anthropic](https://www.anthropic.com); Llama 2, created by [Meta](https://ai.meta.com/llama/), and ChatGPT.
9292

9393
**IDE-based chatbots**
9494

@@ -150,4 +150,4 @@ Code in these boxes was written by AI.
150150

151151
## About This Book
152152

153-
We used AI bots (including ChatGPT, Bard, Sage, and Claude) to develop and write much of this course. We firmly believe this new technology can be used in ethical ways and we put into practice all the rules and suggestions offered over the following modules while we created this book.
153+
We used AI bots (including ChatGPT, Bard, Sage, and Claude) as part of the process of creating this book. The words are all original content, but we used AI bots to edit for grammar and tone. We firmly believe this new technology can be used in ethical ways and we put into practice all the rules and suggestions offered over the following modules while we created this book.

docs/no_toc/03-writing_code.md

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -477,40 +477,6 @@ What are the pros and cons of using Python vs Java for this project?
477477
<img src="resources/images/03-writing_code_files/figure-html//1MCNeSO4aOm1iESWDLOGTcx3aLEbnu8UttV0QGVAeafE_g230c4a00725_31_0.png" title="Claude-instant directly compares Python and Java as languages for the blackjack game, suggesting Python is best for a simple game and Java is better if you want to build a more complex game." alt="Claude-instant directly compares Python and Java as languages for the blackjack game, suggesting Python is best for a simple game and Java is better if you want to build a more complex game." width="100%" style="display: block; margin: auto;" />
478478

479479

480-
481-
## Hands On Exercise
482-
483-
Now it’s your turn to try!
484-
485-
### Code
486-
487-
Here's the code you need for question #2.
488-
489-
```
490-
def calculate_average(numbers):
491-
total = 0
492-
for number in numbers:
493-
total += number
494-
average = total / len(numbers)
495-
return average
496-
497-
numbers = [1, 2, 3, 4, "5"]
498-
average = calculate_average(numbers)
499-
print("The average of the numbers is:", average)
500-
```
501-
502-
### Questions
503-
504-
1. Write a prompt to create a function that replaces all instances of the string "three" with the number 3, then create a prompt that allows you to modify the function so that "three", "Three", and "THREE" are all replaced with the number 3.
505-
506-
1. Write a query that helps you debug the code snippet from above.
507-
508-
1. Create a query that explains how to retrieve data from an online database. Don't forget to find out what the source of the code is.
509-
510-
1. Write a prompt to plan out a program that creates and plays a game of Rock, Paper, Scissors. You should create a multi-step plan as well as figure out what your first coding task should be.
511-
512-
1. Create a prompt that identifies the best coding language for the above game.
513-
514480
## Summary
515481

516482
* Coding has become an essential skill in today's world. AI can increase the efficiency of planning, writing, and debugging code, as well as make coding more accessible for beginners.
@@ -538,7 +504,7 @@ devtools::session_info()
538504
## collate en_US.UTF-8
539505
## ctype en_US.UTF-8
540506
## tz Etc/UTC
541-
## date 2023-08-22
507+
## date 2023-11-01
542508
##
543509
## ─ Packages ───────────────────────────────────────────────────────────────────
544510
## package * version date lib source
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
2+
3+
4+
5+
# Writing Code: Hands-On Exercise
6+
7+
Now it’s your turn to try!
8+
9+
## Code
10+
11+
Here's the code you need for question #2.
12+
13+
```
14+
def calculate_average(numbers):
15+
total = 0
16+
for number in numbers:
17+
total += number
18+
average = total / len(numbers)
19+
return average
20+
21+
numbers = [1, 2, 3, 4, "5"]
22+
average = calculate_average(numbers)
23+
print("The average of the numbers is:", average)
24+
```
25+
26+
## Questions
27+
28+
1. Write a prompt to create a function that replaces all instances of the string "three" with the number 3, then create a prompt that allows you to modify the function so that "three", "Three", and "THREE" are all replaced with the number 3.
29+
30+
1. Write a query that helps you debug the code snippet from above.
31+
32+
1. Create a query that explains how to retrieve data from an online database. Don't forget to find out what the source of the code is.
33+
34+
1. Write a prompt to plan out a program that creates and plays a game of Rock, Paper, Scissors. You should create a multi-step plan as well as figure out what your first coding task should be.
35+
36+
1. Create a prompt that identifies the best coding language for the above game.
37+
38+
39+
40+
41+
```r
42+
devtools::session_info()
43+
```
44+
45+
```
46+
## ─ Session info ───────────────────────────────────────────────────────────────
47+
## setting value
48+
## version R version 4.0.2 (2020-06-22)
49+
## os Ubuntu 20.04.5 LTS
50+
## system x86_64, linux-gnu
51+
## ui X11
52+
## language (EN)
53+
## collate en_US.UTF-8
54+
## ctype en_US.UTF-8
55+
## tz Etc/UTC
56+
## date 2023-11-01
57+
##
58+
## ─ Packages ───────────────────────────────────────────────────────────────────
59+
## package * version date lib source
60+
## assertthat 0.2.1 2019-03-21 [1] RSPM (R 4.0.5)
61+
## bookdown 0.24 2023-03-28 [1] Github (rstudio/bookdown@88bc4ea)
62+
## bslib 0.4.2 2022-12-16 [1] CRAN (R 4.0.2)
63+
## cachem 1.0.7 2023-02-24 [1] CRAN (R 4.0.2)
64+
## callr 3.5.0 2020-10-08 [1] RSPM (R 4.0.2)
65+
## cli 3.6.1 2023-03-23 [1] CRAN (R 4.0.2)
66+
## crayon 1.3.4 2017-09-16 [1] RSPM (R 4.0.0)
67+
## desc 1.2.0 2018-05-01 [1] RSPM (R 4.0.3)
68+
## devtools 2.3.2 2020-09-18 [1] RSPM (R 4.0.3)
69+
## digest 0.6.25 2020-02-23 [1] RSPM (R 4.0.0)
70+
## ellipsis 0.3.1 2020-05-15 [1] RSPM (R 4.0.3)
71+
## evaluate 0.20 2023-01-17 [1] CRAN (R 4.0.2)
72+
## fansi 0.4.1 2020-01-08 [1] RSPM (R 4.0.0)
73+
## fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.0.2)
74+
## fs 1.5.0 2020-07-31 [1] RSPM (R 4.0.3)
75+
## glue 1.4.2 2020-08-27 [1] RSPM (R 4.0.5)
76+
## hms 0.5.3 2020-01-08 [1] RSPM (R 4.0.0)
77+
## htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.0.2)
78+
## jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.0.2)
79+
## jsonlite 1.7.1 2020-09-07 [1] RSPM (R 4.0.2)
80+
## knitr 1.33 2023-03-28 [1] Github (yihui/knitr@a1052d1)
81+
## lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.0.2)
82+
## magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.0.2)
83+
## memoise 2.0.1 2021-11-26 [1] CRAN (R 4.0.2)
84+
## ottrpal 1.0.1 2023-03-28 [1] Github (jhudsl/ottrpal@151e412)
85+
## pillar 1.9.0 2023-03-22 [1] CRAN (R 4.0.2)
86+
## pkgbuild 1.1.0 2020-07-13 [1] RSPM (R 4.0.2)
87+
## pkgconfig 2.0.3 2019-09-22 [1] RSPM (R 4.0.3)
88+
## pkgload 1.1.0 2020-05-29 [1] RSPM (R 4.0.3)
89+
## prettyunits 1.1.1 2020-01-24 [1] RSPM (R 4.0.3)
90+
## processx 3.4.4 2020-09-03 [1] RSPM (R 4.0.2)
91+
## ps 1.4.0 2020-10-07 [1] RSPM (R 4.0.2)
92+
## R6 2.4.1 2019-11-12 [1] RSPM (R 4.0.0)
93+
## readr 1.4.0 2020-10-05 [1] RSPM (R 4.0.2)
94+
## remotes 2.2.0 2020-07-21 [1] RSPM (R 4.0.3)
95+
## rlang 1.1.0 2023-03-14 [1] CRAN (R 4.0.2)
96+
## rmarkdown 2.10 2023-03-28 [1] Github (rstudio/rmarkdown@02d3c25)
97+
## rprojroot 2.0.3 2022-04-02 [1] CRAN (R 4.0.2)
98+
## sass 0.4.5 2023-01-24 [1] CRAN (R 4.0.2)
99+
## sessioninfo 1.1.1 2018-11-05 [1] RSPM (R 4.0.3)
100+
## stringi 1.5.3 2020-09-09 [1] RSPM (R 4.0.3)
101+
## stringr 1.4.0 2019-02-10 [1] RSPM (R 4.0.3)
102+
## testthat 3.0.1 2023-03-28 [1] Github (R-lib/testthat@e99155a)
103+
## tibble 3.2.1 2023-03-20 [1] CRAN (R 4.0.2)
104+
## usethis 1.6.3 2020-09-17 [1] RSPM (R 4.0.2)
105+
## utf8 1.1.4 2018-05-24 [1] RSPM (R 4.0.3)
106+
## vctrs 0.6.1 2023-03-22 [1] CRAN (R 4.0.2)
107+
## withr 2.3.0 2020-09-22 [1] RSPM (R 4.0.2)
108+
## xfun 0.26 2023-03-28 [1] Github (yihui/xfun@74c2a66)
109+
## yaml 2.2.1 2020-02-01 [1] RSPM (R 4.0.3)
110+
##
111+
## [1] /usr/local/lib/R/site-library
112+
## [2] /usr/local/lib/R/library
113+
```
114+
115+

docs/no_toc/04-refactoring.md

Lines changed: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ proc.time() - start_time
553553

554554
```
555555
## user system elapsed
556-
## 242.413 0.109 242.526
556+
## 223.492 0.121 223.651
557557
```
558558

559559
:::{.query}
@@ -581,7 +581,7 @@ proc.time() - start_time
581581

582582
```
583583
## user system elapsed
584-
## 0.689 0.344 0.862
584+
## 0.533 0.315 0.558
585585
```
586586

587587
The `outer()` function performs the same calculation as the nested loop in the original code, but more efficiently. It returns a matrix of all possible combinations of x and y values, with each element of the matrix being the product of the corresponding x and y values. The `rowSums()` function is then used to sum the elements of each row of the matrix, which is equivalent to summing the products of x and y for each index `i` in the original loop. This method avoids the need for the nested loop, resulting in a faster and more efficient computation.
@@ -609,7 +609,7 @@ proc.time() - start_time
609609

610610
```
611611
## user system elapsed
612-
## 0.364 0.348 0.480
612+
## 0.292 0.236 0.341
613613
```
614614

615615
One optimized way to perform the same calculation is by using the `%*%` operator to perform matrix multiplication. This can be done by converting x and y to matrices and transposing one of them so that their dimensions align for matrix multiplication. This code should be much faster than the original implementation because it takes advantage of highly optimized matrix multiplication algorithms in R.
@@ -643,90 +643,6 @@ Because AI models are created by humans, they can be biased. This means they may
643643

644644
When using AI to refactor code, the code itself is often sent to an external service or platform for analysis and transformation. This can raise concerns about the security of the code, especially if it contains sensitive information such as trade secrets, proprietary algorithms, or personal data. If your code is sensitive, it's important to carefully vet any third-party AI tools or services used in the refactoring process.
645645

646-
## Hands-On Exercise
647-
648-
Now it's your turn to try.
649-
650-
### The Code
651-
652-
Let's say you are dusting off some code from your past (no judgment here). You were investigating tweets about [Mr. Trash Wheel](https://www.mrtrashwheel.com/), a beloved Baltimore-based contraption that filters trash out of the waterways.
653-
654-
**Note**: This code is just an example and was written strictly for educational purposes.
655-
656-
657-
```python
658-
import tweepy
659-
import pandas
660-
661-
# Enter your API keys and access tokens here
662-
consumer_key = 'your_consumer_key'
663-
consumer_secret = "your_consumer_secret"
664-
access_token = 'your_access_token'
665-
access_token_secret = 'your_access_token_secret'
666-
667-
# Authenticate with Twitter API
668-
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
669-
auth.set_access_token(access_token, access_token_secret)
670-
671-
# Search for tweets containing the search term
672-
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q="Mr. Trash Wheel", tweet_mode='extended').items(100)
673-
674-
# Create empty list to store tweet data
675-
date_data = []
676-
location_data = []
677-
text_data = []
678-
679-
def get_tweet_length(tweet):
680-
# Return the length of the tweet text
681-
return len(tweet.full_text)
682-
683-
# Loop through each tweet and extract desired data
684-
for tweet in tweets:
685-
date_info = {
686-
'date': tweet.created_at
687-
}
688-
date_data.append(date_info)
689-
690-
# Search for tweets containing the search term
691-
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q="Mr. Trash Wheel", tweet_mode='extended').items(100)
692-
693-
# Loop through each tweet and extract desired data
694-
for tweet in tweets:
695-
location_info = {
696-
'location': tweet.user.location
697-
}
698-
location_data.append(location_info)
699-
700-
# Search for tweets containing the search term
701-
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q='Mr. Trash Wheel', tweet_mode='extended').items(100)
702-
703-
# Loop through each tweet and extract desired data
704-
for tweet in tweets:
705-
text_info = {
706-
'text': tweet.full_text
707-
}
708-
text_data.append(text_info)
709-
710-
# Combine lists into a dictionary
711-
data = {'date': date_data,
712-
'location': location_data, 'text': text_data}
713-
714-
# Store results in pandas dataframe
715-
df = pandas.DataFrame(data)
716-
717-
# Print dataframe
718-
print(df)
719-
```
720-
721-
### Questions
722-
723-
1. Create an AI prompt that fixes any formatting issues with the code that would cause it not to run.
724-
725-
1. Devise an AI prompt that removes any dead code from your sample above. What gets removed?
726-
727-
1. Create a prompt that makes the code less repetitive, adhering to the DRY principle. What aspect of the code was repetitive?
728-
729-
1. Construct a prompt that makes the code more concise. What are some trade-offs that appear in this code between readability and brevity?
730646

731647
## Summary
732648

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
3+
4+
5+
# Refactoring Code: Hands-On Exercise
6+
7+
Now it's your turn to try.
8+
9+
## The Code
10+
11+
Let's say you are dusting off some code from your past (no judgment here). You were investigating tweets about [Mr. Trash Wheel](https://www.mrtrashwheel.com/), a beloved Baltimore-based contraption that filters trash out of the waterways.
12+
13+
**Note**: This code is just an example and was written strictly for educational purposes.
14+
15+
16+
```python
17+
import tweepy
18+
import pandas
19+
20+
# Enter your API keys and access tokens here
21+
consumer_key = 'your_consumer_key'
22+
consumer_secret = "your_consumer_secret"
23+
access_token = 'your_access_token'
24+
access_token_secret = 'your_access_token_secret'
25+
26+
# Authenticate with Twitter API
27+
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
28+
auth.set_access_token(access_token, access_token_secret)
29+
30+
# Search for tweets containing the search term
31+
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q="Mr. Trash Wheel", tweet_mode='extended').items(100)
32+
33+
# Create empty list to store tweet data
34+
date_data = []
35+
location_data = []
36+
text_data = []
37+
38+
def get_tweet_length(tweet):
39+
# Return the length of the tweet text
40+
return len(tweet.full_text)
41+
42+
# Loop through each tweet and extract desired data
43+
for tweet in tweets:
44+
date_info = {
45+
'date': tweet.created_at
46+
}
47+
date_data.append(date_info)
48+
49+
# Search for tweets containing the search term
50+
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q="Mr. Trash Wheel", tweet_mode='extended').items(100)
51+
52+
# Loop through each tweet and extract desired data
53+
for tweet in tweets:
54+
location_info = {
55+
'location': tweet.user.location
56+
}
57+
location_data.append(location_info)
58+
59+
# Search for tweets containing the search term
60+
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q='Mr. Trash Wheel', tweet_mode='extended').items(100)
61+
62+
# Loop through each tweet and extract desired data
63+
for tweet in tweets:
64+
text_info = {
65+
'text': tweet.full_text
66+
}
67+
text_data.append(text_info)
68+
69+
# Combine lists into a dictionary
70+
data = {'date': date_data,
71+
'location': location_data, 'text': text_data}
72+
73+
# Store results in pandas dataframe
74+
df = pandas.DataFrame(data)
75+
76+
# Print dataframe
77+
print(df)
78+
```
79+
80+
## Questions
81+
82+
1. Create an AI prompt that fixes any formatting issues with the code that would cause it not to run.
83+
84+
1. Devise an AI prompt that removes any dead code from your sample above. What gets removed?
85+
86+
1. Create a prompt that makes the code less repetitive, adhering to the DRY principle. What aspect of the code was repetitive?
87+
88+
1. Construct a prompt that makes the code more concise. What are some trade-offs that appear in this code between readability and brevity?
89+

docs/no_toc/05-annotation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ devtools::session_info()
374374
## collate en_US.UTF-8
375375
## ctype en_US.UTF-8
376376
## tz Etc/UTC
377-
## date 2023-08-22
377+
## date 2023-11-01
378378
##
379379
## ─ Packages ───────────────────────────────────────────────────────────────────
380380
## package * version date lib source

0 commit comments

Comments
 (0)