Skip to content

Commit 5e7a5bb

Browse files
author
Daniel Bank
authored
Tagging codeblocks (#53)
1 parent 0ea6d3c commit 5e7a5bb

20 files changed

Lines changed: 140 additions & 149 deletions

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,34 @@ Of course [crates.io](https://crates.io) where you get you some crates.
1818

1919
Want to give a talk at our meetup? Want to hear more about a particular topic? Here are some topic ideas ...
2020

21-
* wasm
22-
* embedded
23-
* cli
24-
* networking (futures/coroutines/async await) wont really be ready until 4 months from now anyway
25-
* c/c++ to rust and back, ffi bindings, bindgen, unsafe
26-
* declarative/reactive/functional rust
27-
* web frameworks (api), wasm frontend!
28-
* whats wrong with rust, lightning talks from elixer/reason/ proponents
29-
* cryptography
30-
* cryptocurrency and blockchain
31-
* servo and mozilla
32-
* halloween special, scare me with your worst procedural macros
33-
* Patterns (prelude, alias, that github, unwrap_or_else match and ?)
34-
* antipatterns
35-
* mobile ios android
36-
21+
- wasm
22+
- embedded
23+
- cli
24+
- networking (futures/coroutines/async await) wont really be ready until 4 months from now anyway
25+
- c/c++ to rust and back, ffi bindings, bindgen, unsafe
26+
- declarative/reactive/functional rust
27+
- web frameworks (api), wasm frontend!
28+
- whats wrong with rust, lightning talks from elixer/reason/ proponents
29+
- cryptography
30+
- cryptocurrency and blockchain
31+
- servo and mozilla
32+
- halloween special, scare me with your worst procedural macros
33+
- Patterns (prelude, alias, that github, unwrap_or_else match and ?)
34+
- antipatterns
35+
- mobile ios android
3736

3837
## Building the site locally
38+
3939
[Install zola](https://www.getzola.org/documentation/getting-started/installation/) then:
40-
```
40+
41+
```bash
4142
git clone --recursive git@github.com:azdevs/desert-rustaceans.git
4243
cd desert-rustaceans
4344
zola build && zola serve
4445
```
46+
4547
And you'll see your the url the local server is available at
4648

47-
Check out the rest of the docs on that page. Help always wanted, and were not tied to this theme at all.
49+
Check out the rest of the docs on that page. Help always wanted, and were not tied to this theme at all.
4850

49-
Pushes to master automatically deploy to our github pages via travis
51+
Pushes to master automatically deploy to our github pages via travis

content/2019-05-22.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,3 @@ I like [Rocket](https://rocket.rs) because it focuses heavily on programmer ergo
106106
```
107107

108108
the parent is used to pick the layout - this is totally by convention and can be omitted for pages that aren't laid out
109-
110-
```
111-
112-
```

content/2019-07-24.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ We can technically compile just fine for rapsberry pi if we add the target:
2121

2222
But well get this error when we build for our target
2323

24-
```bash
24+
```console
2525
$ cargo build --target armv7-unknown-linux-gnueabihf
2626
Compiling pi-example v0.1.0 (/Users/jacobrosenthal/Downloads/pi-example)
2727
error: linker `arm-linux-gnueabihf-gcc` not found
@@ -44,7 +44,7 @@ So if were in linux its probably actually [not that hard to get the raspberry pi
4444

4545
Then create a .cargo/config file and add
4646

47-
```
47+
```toml
4848
[build]
4949
target = "armv7-unknown-linux-gnueabihf"
5050

@@ -96,8 +96,8 @@ But you know whats better than doing all that yourself and polluting your machin
9696

9797
- Are you getting errors similar to the following?
9898

99-
```bash
100-
error: failed to load source for a dependency on \`tract-core\`
99+
```console
100+
error: failed to load source for a dependency on \`tract-core\`
101101
```
102102

103103
I was able to resolve these errors by specifying a `--manifest-path`:
@@ -106,9 +106,9 @@ But you know whats better than doing all that yourself and polluting your machin
106106
cross build --target=armv7-unknown-linux-gnueabihf --manifest-path=examples/tensorflow-mobilenet-v2/Cargo.toml
107107
```
108108

109-
- Is there a supported Docker image for the target architecture? I noticed when trying to build for a Pi Zero that I couldn't find a Docker image for the `arm-unknown-linux-gnueabihf` target. In my case, someone published their own [Docker image](https://hub.docker.com/r/rustreleaser/cross) which I found from a [GitHub Issue](https://github.com/rust-embedded/cross/issues/261)
109+
- Is there a supported Docker image for the target architecture? I noticed when trying to build for a Pi Zero that I couldn't find a Docker image for the `arm-unknown-linux-gnueabihf` target. In my case, someone published their own [Docker image](https://hub.docker.com/r/rustreleaser/cross) which I found from a [GitHub Issue](https://github.com/rust-embedded/cross/issues/261)
110110

111-
```bash
111+
```console
112112
Unable to find image 'japaric/arm-unknown-linux-gnueabihf:latest' locally
113113
```
114114

content/2019-08-28.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The smallest spa you could start with is a little Wasm app that mutates the DOM
7777

7878
In src/lib.rs should look pretty familiar. We're leaning on the [web-sys](https://github.com/rustwasm/wasm-bindgen/tree/master/crates/web-sys) another wasm wg joint. These are autogenerated bindings to all the [web api](https://developer.mozilla.org/en-US/docs/Web/API).
7979

80-
```
80+
```rust
8181
let window = web_sys::window().expect("no global `window` exists");
8282
let document = window.document().expect("should have a document on window");
8383
let body = document.body().expect("document should have a body");
@@ -95,7 +95,7 @@ In src/lib.rs should look pretty familiar. We're leaning on the [web-sys](https:
9595
9696
Then `wasm-pack` tool which drives Cargo will generate our wasm output.
9797

98-
```
98+
```console
9999
$ cargo install wasm-pack
100100
$ wasm-pack build --target web
101101
$ ls pkg/
@@ -126,7 +126,7 @@ We still need efficient dom updates. Many people are working across many differe
126126

127127
Who wants to write Rust though? Cant I have a JSX style html dsl? Yes, I have several to sell you but lets focus on [typed-html](https://github.com/bodil/typed-html)
128128

129-
```
129+
```rust
130130
let mut doc: DOMTree<String> = html!(
131131
<html>
132132
<head>

content/2019-09-25.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ Then crate a new library we can link with `cargo new --lib add1` `cd add1`
3636

3737
Next, we need to specify a special kind of library by adding this to this to the Cargo.toml
3838

39-
```
39+
```toml
4040
[lib]
4141
crate-type = ["cdylib"]
4242
```
4343

4444
Then add this to our lib.rs a simple function that we can call from javascript
4545

46-
```
46+
```rust
4747
#[no_mangle]
4848
pub extern "C" fn add_one(x: i32) -> i32 {
4949
x+1
@@ -96,7 +96,7 @@ Lets try
9696
`touch add1.wat`
9797
and all all this to it
9898

99-
```
99+
```console
100100
(module
101101
(func $add_one (param $lhs i32) (result i32)
102102
local.get $lhs
@@ -111,7 +111,7 @@ and all all this to it
111111
We can look inside our wasm file to see a ton of stuff including what functions it exports
112112
`wasm-objdump -x target/wasm32-unknown-unknown/release/add1.wasm`
113113

114-
```
114+
```console
115115
...
116116
Custom:
117117
- name: "name"
@@ -165,7 +165,7 @@ notice this is a binary not a library, and notice no annotations or anything lik
165165

166166
Lets add something that uses a syscall to main.rs to read text from the command line and write it back out
167167

168-
```
168+
```rust
169169
use std::io::{self, BufRead};
170170

171171
fn main() {

content/2019-10-24.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ For those not in the know say someone says you need the nightly build of a cargo
101101

102102
`cargo new helloworld && cd helloworld`
103103

104-
```bash
104+
```console
105105
$ cargo asm helloworld::main --rust
106106
fn main() {
107107
push rbp
@@ -163,7 +163,7 @@ fn main() { }
163163

164164
The compiler makes sure things compile, clippy tries to tell you there might be a better way to do things. You can replace 'check' in your ide with 'clippy' or run it on the command line.
165165

166-
```bash
166+
```console
167167
$ cargo clippy
168168
warning: casting u32 to f64 may become silently lossy if you later change the type
169169
--> src/bin.rs:166:51
@@ -180,7 +180,7 @@ $
180180

181181
Note you have it installed on nightly, it can also apply the suggestion automatically.
182182

183-
```bash
183+
```console
184184
$ cargo +nightly fix -Z unstable-options --clippy
185185
$ cargo clippy
186186
Finished dev [unoptimized + debuginfo] target(s) in 0.57s
@@ -227,7 +227,7 @@ let matches = App::new("next-prime")
227227

228228
> Statements are instructions that perform some action and do not return a value. Expressions evaluate to a resulting value.
229229
230-
```
230+
```console
231231
error[E0308]: mismatched types
232232
--> src/main.rs:4:26
233233
|

content/2020-02-26.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Topics:
2323

2424
I'm working on making an example app for the PyGamer which allows the user to draw numbers and the app infers what number is drawn. I want to use a model that was trained on the [MNIST dataset](http://yann.lecun.com/exdb/mnist/), load it in the app, and use it to run inference. I found a crate called [tch](https://crates.io/crates/tch), which is Rust bindings for the [PyTorch C++ API](https://pytorch.org/cppdocs/). There is some [example code](https://github.com/LaurentMazare/tch-rs/issues/50) in a GitHub Issue for saving / loading models. Now I just need to build it for an embedded system. Is it possible? I can add the `#![no_std]` pragma and it still builds. When I add the `#![no_main]` pragma, the build fails with an error:
2525

26-
```
26+
```console
2727
error: linking with `cc` failed: exit code: 1
2828
|
2929
...

content/2020-06-24.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Andrew presented on Rust's portability by creating a crate for visualizing the M
3333

3434
For the Python package, he used [pyo3](https://crates.io/crates/pyo3) to generate a native Python module. He then used the module in a Jupyter notebook simply with:
3535

36-
```
36+
```rust
3737
from matplotlib import pyplot as plt
3838
from mandelbrot_rs import generate
3939

@@ -65,7 +65,7 @@ He ended up forking the [oauth2](https://crates.io/crates/oauth2) crate so that
6565

6666
Finally, Blaine demonstrated using `field(guard())` macros for locking down mutations:
6767

68-
```
68+
```rust
6969
pub struct PermissionGuard {
7070
pub permission: Permission,
7171
}
@@ -89,7 +89,7 @@ impl Guard for PermissionGuard {
8989

9090
And used in the mutation:
9191

92-
```
92+
```rust
9393
#[field(guard(PermissionGuard(permission = "Permission::CreateWaves")))]
9494
pub async fn add_wave(&self, ctx: &Context<'_>, wave: WaveInput) -> FieldResult<Wave> { ... }
9595
```

content/2020-07-29.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ We saw a bunch of new stuff.
114114

115115
The result is four 1s and the rest zeros.
116116

117-
```bash
117+
```console
118118
"window": 1.0000, 1.0000, 1.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
119119
⡉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉ 1.0
120120
@@ -141,7 +141,7 @@ A digression. An exponential signal looks like
141141
let exponential = (0..(N::to_usize())).map(|val| A.powf(val as f32));
142142
```
143143

144-
```bash
144+
```console
145145
"exponential": 1.0000, 0.8000, 0.6400, 0.5120, 0.4096, 0.3277, 0.2621, 0.2097, 0.1678, 0.1342
146146
⡁ 1.0
147147
@@ -168,7 +168,7 @@ Now we can filter our exponential signal with our window signal.
168168
let exp_window = exponential.zip(window).map(|(ex, x5)| ex * x5);
169169
```
170170

171-
```
171+
```console
172172
"exp_window": 1.0000, 0.8000, 0.6400, 0.5120, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
173173
⡁ 1.0
174174

content/2020-08-26.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,28 @@ I found that the best place to learn how to use tch to make a linear regression
3535

3636
The main challenge I faced in making the example was when I wanted to utilize the linear regression model in the prediction route. The model is created in `main()`:
3737

38-
```
38+
```rust
3939
let mut vs = nn::VarStore::new(Device::Cpu);
4040
let linear = net(&vs.root());
4141
```
4242

4343
The first (naive) approach I attempted was to pass it directly to the prediction route by having Rocket manage it as state:
4444

45-
```
45+
```rust
4646
rocket::ignite()
4747
.manage(linear)
4848
.mount("/", routes![index]).launch();
4949
```
5050

5151
The type of `linear` is [`impl Module`](https://doc.rust-lang.org/edition-guide/rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.html#return-position) or "a type that implement nn::Module". Trouble arises when I try to wrap this in State in the definition for the route handler:
5252

53-
```
53+
```rust
5454
fn predict(bmi: Form<BMI>, classifier_state: State<impl Module>) -> std::string::String { ... }
5555
```
5656

5757
This line then reports an error:
5858

59-
```
59+
```console
6060
`impl Module` cannot be shared between threads safely
6161

6262
help: consider further restricting this bound: ` + std::marker::Sync`rustc(E0277)
@@ -67,7 +67,7 @@ state.rs(106, 32): required by this bound in `rocket::State`
6767

6868
In this case, the advice for this error is not particularly helpful because further restricting the bounds only changes the error:
6969

70-
```
70+
```console
7171
the size for values of type `(dyn tch::nn::Module + std::marker::Sync + 'static)` cannot be known at compilation time
7272

7373
doesn't have a size known at compile-time
@@ -77,15 +77,15 @@ help: the trait `std::marker::Sized` is not implemented for `(dyn tch::nn::Modul
7777

7878
The solution I found was to use a [mutex](https://doc.rust-lang.org/std/sync/struct.Mutex.html) to ensure that shared access to the model in the route and main thread is protected. The `main()` function becomes:
7979

80-
```
80+
```rust
8181
rocket::ignite()
8282
.manage(Mutex::new(Box::new(linear) as Box<dyn Module>))
8383
.mount("/", routes![index, predict]).launch();
8484
```
8585

8686
And the definition of the route handler becomes:
8787

88-
```
88+
```rust
8989
fn predict(bmi: Form<BMI>, classifier_mutex: State<Mutex<Box<dyn Module>>>) -> std::string::String { ... }
9090
```
9191

@@ -123,7 +123,7 @@ Jacob made an [example program using smol](https://github.com/jacobrosenthal/sht
123123

124124
`smol::channel::unbounded` gives you a sender and receiver:
125125

126-
```
126+
```rust
127127
smol::block_on(async {
128128
...
129129
let (sender, receiver) = smol::channel::unbounded();
@@ -133,7 +133,7 @@ Jacob made an [example program using smol](https://github.com/jacobrosenthal/sht
133133

134134
`smol::Timer::after` is the async version of `std::thread::sleep`
135135

136-
```
136+
```rust
137137
async fn show(
138138
receiver: Receiver<(Measurement, Measurement)>,
139139
) -> Result<(), smol::channel::RecvError> {

0 commit comments

Comments
 (0)