Skip to content

Commit

Permalink
Remove slides that are in the notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
sualeh committed May 5, 2024
1 parent 9222f79 commit 9a2e09c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 105 deletions.
31 changes: 1 addition & 30 deletions Slides/part2/what-a-character-encoding-java.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Encoding in Java



## Encoding
## Encoding

See the [presentation on encoding concepts](https://sualeh.github.io/What-a-Character/what-a-character-encoding.pdf).

Expand All @@ -58,35 +58,6 @@ See the [presentation on encoding concepts](https://sualeh.github.io/What-a-Char
- Every encoding has a **canonical name** or MIME-preferred name


## Converting to Bytes

```java
String original = ....
byte[] utf8Bytes = original.getBytes("UTF-8");
String roundTrip = new String(utf8Bytes, "UTF-8");
// and remember to handle encoding exceptions
```


## Reading Unicode

- Use readers to decode

```java
InputStream fis = new FileInputStream("in.txt");
Reader rdr = new InputStreamReader(fis, "UTF-8");
```

## Writing Unicode

- Use writers to encode

```java
OutputStream fos = new FileOutputStream("out.txt");
Writer wtr = new OutputStreamWriter(fos, "UTF-8");
```


## Code Examples

Slides and all code examples are on GitHub
Expand Down
41 changes: 1 addition & 40 deletions Slides/part2/what-a-character-encoding-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ Encoding in JavaScript
**Sualeh Fatehi**



## Encoding
## Encoding

See the [presentation on encoding concepts](https://sualeh.github.io/What-a-Character/what-a-character-encoding.pdf).

![bg right opacity:.5](../common/rosetta-stone.jpg "Rosetta Stone")




## `TextEncoder` and `TextDecoder`

- Provide functions for encoding and decoding
Expand All @@ -48,42 +45,6 @@ See the [presentation on encoding concepts](https://sualeh.github.io/What-a-Char
- Handles encoding and decoding errors


## Converting to Bytes

- Always specify encoding to avoid cross-platform surprises

```javascript
original = ...
utf8Bytes = new TextEncoder().encode(original);
roundTrip = new TextDecoder("utf-8").decode(utf8Bytes);
```


## Reading Unicode

Specify encoding when opening a file.

```javascript
const fs = require('fs');
fs.readFile('test.txt', 'utf-8', function (err, data) {
// Ignore errors, print what was read
console.log(data);
});
```


## Writing Unicode

Specify `encoding` when opening a file.

```javascript
const fs = require('fs');
fs.writeFile('test.txt', string, 'utf-8', function (err) {
// Ignore errors, write `string`
});
```


## Code Examples

Slides and all code examples are on GitHub
Expand Down
36 changes: 1 addition & 35 deletions Slides/part2/what-a-character-encoding-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ Encoding in Python
**Sualeh Fatehi**



## Encoding
## Encoding

See the [presentation on encoding concepts](https://sualeh.github.io/What-a-Character/what-a-character-encoding.pdf).

![bg right opacity:.5](../common/rosetta-stone.jpg "Rosetta Stone")




## `codecs` Module

- Provides functions for encoding and decoding
Expand All @@ -48,37 +45,6 @@ See the [presentation on encoding concepts](https://sualeh.github.io/What-a-Char
- Handles encoding and decoding errors


## Converting to Bytes

- Always specify encoding to avoid cross-platform surprises

```python
original: str = ...
utf8_bytes = codecs.encode(original, "utf-8")
round_trip = codecs.decode(utf8_bytes, "utf-8")
```


## Reading Unicode

Specify `encoding` when opening a file.

```python
with open("test.txt", "r", encoding="utf-8") as reader:
print(reader.read())
```


## Writing Unicode

Specify `encoding` when opening a file.

```python
with open("test.txt", "w", encoding="utf-8") as writer:
writer.write(string)
```


## Code Examples

Slides and all code examples are on GitHub
Expand Down

0 comments on commit 9a2e09c

Please sign in to comment.